Example #1
0
        private dynamic CastSchemaItemType(object arg, ValueType itemType)
        {
            if ((arg is string) && ((itemType == ValueType.Int) || itemType == ValueType.Decimal || itemType == ValueType.Long || itemType == ValueType.Double))
            {
                if (arg.ToString().StartsWith("(") && (arg.ToString().EndsWith(")")))
                {
                    arg = arg.ToString().Replace("(", "-").Replace(")", "");
                }
            }
            var type = ConvertValueType(itemType);

            if (type == null)
            {
                return(arg);
            }
            var argType = arg.GetType();

            if (argType == type)
            {
                return(arg);
            }

            var cast = _castProvider.Value.GetCast(argType, type);

            return(cast != null
                ? cast(arg)
                : Impromptu.InvokeConvert(arg, type, true));
        }
Example #2
0
 private static Type ConvertValueType(ValueType itemType)
 {
     if (SupportedTypes.TryGetValue(itemType, out var result))
     {
         return(result);
     }
     throw new ArgumentOutOfRangeException(nameof(itemType), itemType, "Unsupported type");
 }