Abc.Zebus.TinyHost.Configuration.ConfigurationValueConverter.ConvertValueString C# (CSharp) Метод

ConvertValueString() приватный статический Метод

private static ConvertValueString ( string value, Type expectedType ) : object
value string
expectedType System.Type
Результат object
        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);
        }