private static object ConvertValueString(string value, Type expectedType)
{
var underlyingType = Nullable.GetUnderlyingType(expectedType);
if (underlyingType != null)
return string.IsNullOrEmpty(value) ? null : ConvertValue(value, underlyingType);
if (expectedType == typeof(TimeSpan))
return TimeSpan.Parse(value, CultureInfo.InvariantCulture);
if (expectedType == typeof(string[]))
return SplitItems(value).ToArray();
if (expectedType == typeof(int[]))
return SplitItems(value).Select(int.Parse).ToArray();
if (expectedType == typeof(long[]))
return SplitItems(value).Select(long.Parse).ToArray();
if (expectedType.IsEnum)
return Enum.Parse(expectedType, value);
if (expectedType == typeof(Guid))
return Guid.Parse(value);
return Convert.ChangeType(value, expectedType, CultureInfo.InvariantCulture);
}