I have the following code:
public static T ParameterFetchValue<T>(string parameterKey)
{
Parameter result = null;
result = ParameterRepository.FetchParameter(parameterKey);
return (T)Convert.ChangeType(result.CurrentValue, typeof(T), CultureInfo.InvariantCulture);
}
The type of result.CurrentValue is a string. I would like to be able to convert this to a Guid but I keep getting the error:
Invalid cast from System.String to System.Guid
This works perfectly with primitive data types ... is there any way to make this work for non-primitive data types?