Esempio n. 1
0
        protected void UpdateOriginalGenericArguments(ref int nullableFlagsIndex)
        {
            if (_originalGenericArguments == null)
            {
                lock (this)
                {
                    if (_originalGenericArguments == null)
                    {
                        var arguments = new List <CachedType>();
#if NET40
                        foreach (var type in OriginalType.GetGenericArguments())
#else
                        foreach (var type in OriginalType.GenericTypeArguments)
#endif
                        {
                            arguments.Add(GetCachedType(type, ref nullableFlagsIndex));
                        }

                        if (arguments.Count == 0)
                        {
                            var elementType = OriginalType.GetElementType();
                            if (elementType != null)
                            {
                                _elementType = GetCachedType(elementType, ref nullableFlagsIndex);
                            }
                        }

                        _originalGenericArguments = arguments.ToArray();
                        _isNullableType           = OriginalType.Name == "Nullable`1";
                        _genericArguments         = _isNullableType ? arguments[0]._originalGenericArguments : _originalGenericArguments;
                        _type = _isNullableType ? ((IEnumerable)_originalGenericArguments).Cast <CachedType>().First().OriginalType : OriginalType;
                    }
                }
            }
        }
Esempio n. 2
0
        private void DeterminePropertyInfo()
        {
            // for example for string PropertyType.GetInterface("IEnumerable`1")
            // is not null, so we must check if type has sub type
            IsCollection =
                OriginalType.GetInterface("IEnumerable`1") != null &&
                OriginalType.GetGenericArguments().Any();
            if (IsCollection)
            {
                var subType = OriginalType.GetGenericArguments().Single();
                OriginalType = subType;
            }

            IsSystemType = OriginalType.Namespace.StartsWith("System");
        }