Пример #1
0
        public object CreateValue()
        {
#if !NETFX_CORE
            ConstructorInfo constructorInfo = ValueType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
#else
            var             constructorInfos = ValueType.GetTypeInfo().DeclaredConstructors;
            ConstructorInfo constructorInfo  = null;
            foreach (var info in constructorInfos)
            {
                if (info.GetParameters().Length == 0)
                {
                    constructorInfo = info;
                }
            }
#endif
            Debug.Assert(constructorInfo != null);
            return(constructorInfo.Invoke(null));
        }
Пример #2
0
        public ImmutableArray <Object> ExtractComponents(params TypeInfo[] componentTypes)
        {
            if (componentTypes == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(componentTypes));
            }

            if (!componentTypes.Any())
            {
                throw Logger.Fatal.ArgumentEmptySequence(nameof(componentTypes));
            }

            if (!componentTypes.Last().IsAssignableFrom(ValueType.GetTypeInfo()))
            {
                throw Logger.Fatal.ArgumentFormat(
                          nameof(componentTypes),
                          SR.NestedResoveResult_LastComponentTypeMustBeAssignableFromT,
                          componentTypes.Last(),
                          ValueType
                          );
            }

            var array = new Object[componentTypes.Length];

            using (var enumerator = Parents.GetEnumerator())
            {
                var atEnd = false;

                for (var i = 0; !atEnd && (i < array.Length - 1); i++)
                {
                    array[i] = NextOfType(enumerator, componentTypes[i], out atEnd);
                }

                array[array.Length - 1] = Value;
            }

            return(array.ToImmutableArray());
        }
Пример #3
0
            public DictionaryQueryModelDetails(Type dictionaryType)
            {
                var args = dictionaryType.GetTypeInfo().GenericTypeArguments;

                KeyType           = args[0];
                ValueType         = args[1];
                OriginalKeyType   = KeyType;
                OriginalValueType = ValueType;

                Type nullableArgument;

                if (KeyType.GetTypeInfo().IsNullable(out nullableArgument))
                {
                    KeyType           = nullableArgument;
                    IsKeyTypeNullable = true;
                }

                if (ValueType.GetTypeInfo().IsNullable(out nullableArgument))
                {
                    ValueType           = nullableArgument;
                    IsValueTypeNullable = true;
                }
            }
Пример #4
0
        public override void Initialize(ParserInitializeArgs args)
        {
            base.Initialize(args);
            if (args.Push(this))
            {
                if (ValueType != null)
                {
                    var style = NumberStyles.None;

                    if (AllowSign)
                    {
                        style |= NumberStyles.AllowLeadingSign;
                    }
                    if (AllowDecimal)
                    {
                        style |= NumberStyles.AllowDecimalPoint;
                    }
                    if (AllowExponent)
                    {
                        style |= NumberStyles.AllowExponent;
                    }

                    var numberFormat = Culture.NumberFormat;

                    if (typeof(decimal) == ValueType)
                    {
                        getValue = text => decimal.Parse(text, style, numberFormat);
                    }
                    else if (typeof(Int16) == ValueType)
                    {
                        getValue = text => Int16.Parse(text, style, numberFormat);
                    }
                    else if (typeof(Int32) == ValueType)
                    {
                        getValue = text => Int32.Parse(text, style, numberFormat);
                    }
                    else if (typeof(Int64) == ValueType)
                    {
                        getValue = text => Int64.Parse(text, style, numberFormat);
                    }
                    else if (typeof(UInt16) == ValueType)
                    {
                        getValue = text => UInt16.Parse(text, style, numberFormat);
                    }
                    else if (typeof(UInt32) == ValueType)
                    {
                        getValue = text => UInt32.Parse(text, style, numberFormat);
                    }
                    else if (typeof(UInt64) == ValueType)
                    {
                        getValue = text => UInt64.Parse(text, style, numberFormat);
                    }
                    else if (typeof(double) == ValueType)
                    {
                        getValue = text => double.Parse(text, style, numberFormat);
                    }
                    else if (typeof(float) == ValueType)
                    {
                        getValue = text => float.Parse(text, style, numberFormat);
                    }
                    else
                    {
#if PCL
                        var parameters  = new [] { typeof(string), typeof(NumberStyles) };
                        var parseMethod = ValueType.GetTypeInfo().DeclaredMethods.FirstOrDefault(r => r.Name == "Parse" && r.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameters));
#else
                        var parseMethod = ValueType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(string), typeof(NumberStyles) }, null);
#endif
                        getValue = text => parseMethod.Invoke(null, new object[] { text, style });
                    }
                }
                args.Pop();
            }
        }