Пример #1
0
        private object To(string value, Type type)
        {
            if (type == typeof(DateTime?))
            {
                return(_apiTypeConverter.ToUtcDateTimeNullable(value));
            }
            else if (type == typeof(int?))
            {
                return(_apiTypeConverter.ToIntNullable(value));
            }
            else if (type == typeof(int))
            {
                return(_apiTypeConverter.ToInt(value));
            }
            else if (type == typeof(List <int>))
            {
                return(_apiTypeConverter.ToListOfInts(value));
            }
            else if (type == typeof(List <string>))
            {
                return(_apiTypeConverter.ToListOfStrings(value));
            }
            else if (type == typeof(bool?))
            {
                // Because currently status is the only boolean and we need to accept published and unpublished statuses.
                return(_apiTypeConverter.ToStatus(value));
            }
            else if (IsNullableEnum(type))
            {
                return(_apiTypeConverter.ToEnumNullable(value, type));
            }

            // It should be the last resort, because it is not exception safe.
            return(Convert.ChangeType(value, type));
        }
Пример #2
0
        private object To(string value, Type type)
        {
            if (type == typeof(DateTime?))
            {
                return(_apiTypeConverter.ToUtcDateTimeNullable(value));
            }
            if (type == typeof(int?))
            {
                return(_apiTypeConverter.ToIntNullable(value));
            }
            if (type == typeof(int))
            {
                return(_apiTypeConverter.ToInt(value));
            }
            if (type == typeof(List <int>))
            {
                return(_apiTypeConverter.ToListOfInts(value));
            }
            if (type == typeof(List <string>))
            {
                return(_apiTypeConverter.ToListOfStrings(value));
            }
            if (IsNullableEnum(type))
            {
                return(_apiTypeConverter.ToEnumNullable(value, type));
            }

            // It should be the last resort, because it is not exception safe.
            return(Convert.ChangeType(value, type));
        }