public virtual object Convert(object sourceValue, Type targetType)
{
Guard.CheckArgumentNotNull(targetType, "targetType");
if (sourceValue == null)
{
if (targetType.IsValueType)
{
if (Nullable.GetUnderlyingType(targetType) == null)
{
throw new InvalidOperationException();
}
}
return null;
}
Type sourceType = sourceValue.GetType();
if (targetType.IsAssignableFrom(sourceType))
{
return sourceValue;
}
return System.Convert.ChangeType(sourceValue, targetType, CultureInfo.InvariantCulture);
}