Generic conversion function doesn't seem to work with Guids

后端 未结 2 1294
忘掉有多难
忘掉有多难 2020-12-24 05:39

I have the following code:

public static T ParameterFetchValue(string parameterKey)
{
    Parameter result = null;

    result = ParameterRepository         


        
2条回答
  •  失恋的感觉
    2020-12-24 06:08

    How about:

    T t = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(text);
    

    Works fine for Guid and most other types.

提交回复
热议问题