示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonArrayContract"/> class.
        /// </summary>
        /// <param name="underlyingType">The underlying type for the contract.</param>
        public JsonArrayContract(Type underlyingType)
            : base(underlyingType)
        {
            ContractType = JsonContractType.Array;
            IsArray      = CreatedType.IsArray;

            bool canDeserialize;

            Type tempCollectionType;

            if (IsArray)
            {
                CollectionItemType               = ReflectionUtils.GetCollectionItemType(UnderlyingType);
                IsReadOnlyOrFixedSize            = true;
                _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);

                canDeserialize          = true;
                IsMultidimensionalArray = (IsArray && UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(underlyingType))
            {
                if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out _genericCollectionDefinitionType))
                {
                    CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0];
                }
                else
                {
                    CollectionItemType = ReflectionUtils.GetCollectionItemType(underlyingType);
                }

                if (underlyingType == typeof(IList))
                {
                    CreatedType = typeof(List <object>);
                }

                if (CollectionItemType != null)
                {
                    _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, CollectionItemType);
                }

                IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection <>));
                canDeserialize        = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out _genericCollectionDefinitionType))
            {
                CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ICollection <>)) ||
                    ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IList <>)))
                {
                    CreatedType = typeof(List <>).MakeGenericType(CollectionItemType);
                }

#if !(NET20 || NET35)
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ISet <>)))
                {
                    CreatedType = typeof(HashSet <>).MakeGenericType(CollectionItemType);
                }
#endif

                _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, CollectionItemType);
                canDeserialize            = true;
                ShouldCreateWrapper       = true;
            }
#if !(NET40 || NET35 || NET20 || PORTABLE40)
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>), out tempCollectionType))
            {
                CollectionItemType = tempCollectionType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>)) ||
                    ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyList <>)))
                {
                    CreatedType = typeof(ReadOnlyCollection <>).MakeGenericType(CollectionItemType);
                }

                _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);
                _parameterizedConstructor        = CollectionUtils.ResolveEnumerableCollectionConstructor(CreatedType, CollectionItemType);
                IsReadOnlyOrFixedSize            = true;
                canDeserialize = HasParameterizedCreatorInternal;
            }
#endif
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable <>), out tempCollectionType))
            {
                CollectionItemType = tempCollectionType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IEnumerable <>)))
                {
                    CreatedType = typeof(List <>).MakeGenericType(CollectionItemType);
                }

                _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, CollectionItemType);

#if !(NET35 || NET20)
                if (!HasParameterizedCreatorInternal && underlyingType.Name == FSharpUtils.FSharpListTypeName)
                {
                    FSharpUtils.EnsureInitialized(underlyingType.Assembly());
                    _parameterizedCreator = FSharpUtils.CreateSeq(CollectionItemType);
                }
#endif

                if (underlyingType.IsGenericType() && underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    _genericCollectionDefinitionType = tempCollectionType;

                    IsReadOnlyOrFixedSize = false;
                    ShouldCreateWrapper   = false;
                    canDeserialize        = true;
                }
                else
                {
                    _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);

                    IsReadOnlyOrFixedSize = true;
                    ShouldCreateWrapper   = true;
                    canDeserialize        = HasParameterizedCreatorInternal;
                }
            }
            else
            {
                // types that implement IEnumerable and nothing else
                canDeserialize      = false;
                ShouldCreateWrapper = true;
            }

            CanDeserialize = canDeserialize;

#if (NET20 || NET35)
            if (CollectionItemType != null && ReflectionUtils.IsNullableType(CollectionItemType))
            {
                // bug in .NET 2.0 & 3.5 that List<Nullable<T>> throws an error when adding null via IList.Add(object)
                // wrapper will handle calling Add(T) instead
                if (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(List <>), out tempCollectionType) ||
                    (IsArray && !IsMultidimensionalArray))
                {
                    ShouldCreateWrapper = true;
                }
            }
#endif

#if !(NET20 || NET35 || NET40)
            Type immutableCreatedType;
            ObjectConstructor <object> immutableParameterizedCreator;
            if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, CollectionItemType, out immutableCreatedType, out immutableParameterizedCreator))
            {
                CreatedType           = immutableCreatedType;
                _parameterizedCreator = immutableParameterizedCreator;
                IsReadOnlyOrFixedSize = true;
                CanDeserialize        = true;
            }
#endif
        }
示例#2
0
        public JsonArrayContract(Type underlyingType) : base(underlyingType)
        {
            bool hasParameterizedCreatorInternal;

            base.ContractType = JsonContractType.Array;
            this.IsArray      = base.CreatedType.IsArray;
            if (this.IsArray)
            {
                this.CollectionItemType    = ReflectionUtils.GetCollectionItemType(base.UnderlyingType);
                base.IsReadOnlyOrFixedSize = true;
                Type[] typeArguments = new Type[] { this.CollectionItemType };
                this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(typeArguments);
                hasParameterizedCreatorInternal       = true;
                this.IsMultidimensionalArray          = this.IsArray && (base.UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(underlyingType))
            {
                if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
                {
                    this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                }
                else
                {
                    this.CollectionItemType = ReflectionUtils.GetCollectionItemType(underlyingType);
                }
                if (underlyingType == typeof(IList))
                {
                    base.CreatedType = typeof(List <object>);
                }
                if (this.CollectionItemType != null)
                {
                    this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                }
                base.IsReadOnlyOrFixedSize      = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection <>));
                hasParameterizedCreatorInternal = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
            {
                this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ICollection <>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IList <>)))
                {
                    Type[] typeArguments = new Type[] { this.CollectionItemType };
                    base.CreatedType = typeof(List <>).MakeGenericType(typeArguments);
                }
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ISet <>)))
                {
                    Type[] typeArguments = new Type[] { this.CollectionItemType };
                    base.CreatedType = typeof(HashSet <>).MakeGenericType(typeArguments);
                }
                this._parameterizedConstructor  = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                hasParameterizedCreatorInternal = true;
                this.ShouldCreateWrapper        = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>), out Type type))
            {
                this.CollectionItemType = type.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyList <>)))
                {
                    Type[] typeArray4 = new Type[] { this.CollectionItemType };
                    base.CreatedType = typeof(ReadOnlyCollection <>).MakeGenericType(typeArray4);
                }
                Type[] typeArguments = new Type[] { this.CollectionItemType };
                this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(typeArguments);
                this._parameterizedConstructor        = CollectionUtils.ResolveEnumerableCollectionConstructor(base.CreatedType, this.CollectionItemType);
                base.IsReadOnlyOrFixedSize            = true;
                hasParameterizedCreatorInternal       = this.HasParameterizedCreatorInternal;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable <>), out type))
            {
                this.CollectionItemType = type.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(base.UnderlyingType, typeof(IEnumerable <>)))
                {
                    Type[] typeArguments = new Type[] { this.CollectionItemType };
                    base.CreatedType = typeof(List <>).MakeGenericType(typeArguments);
                }
                this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                if (!this.HasParameterizedCreatorInternal && (underlyingType.Name == "FSharpList`1"))
                {
                    FSharpUtils.EnsureInitialized(underlyingType.Assembly());
                    this._parameterizedCreator = FSharpUtils.CreateSeq(this.CollectionItemType);
                }
                if (underlyingType.IsGenericType() && (underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                {
                    this._genericCollectionDefinitionType = type;
                    base.IsReadOnlyOrFixedSize            = false;
                    this.ShouldCreateWrapper        = false;
                    hasParameterizedCreatorInternal = true;
                }
                else
                {
                    Type[] typeArguments = new Type[] { this.CollectionItemType };
                    this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(typeArguments);
                    base.IsReadOnlyOrFixedSize            = true;
                    this.ShouldCreateWrapper        = true;
                    hasParameterizedCreatorInternal = this.HasParameterizedCreatorInternal;
                }
            }
            else
            {
                hasParameterizedCreatorInternal = false;
                this.ShouldCreateWrapper        = true;
            }
            this.CanDeserialize = hasParameterizedCreatorInternal;
            if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, this.CollectionItemType, out Type type2, out ObjectConstructor <object> constructor))
            {
                base.CreatedType           = type2;
                this._parameterizedCreator = constructor;
                base.IsReadOnlyOrFixedSize = true;
                this.CanDeserialize        = true;
            }
        }
示例#3
0
        public JsonArrayContract(Type underlyingType) : base(underlyingType)
        {
            this.ContractType = JsonContractType.Array;
            this.IsArray      = (base.CreatedType.IsArray || (this.NonNullableUnderlyingType.IsGenericType() && this.NonNullableUnderlyingType.GetGenericTypeDefinition().FullName == "System.Linq.EmptyPartition`1"));
            bool canDeserialize;
            Type type;

            if (this.IsArray)
            {
                this.CollectionItemType               = ReflectionUtils.GetCollectionItemType(base.UnderlyingType);
                this.IsReadOnlyOrFixedSize            = true;
                this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(new Type[]
                {
                    this.CollectionItemType
                });
                canDeserialize = true;
                this.IsMultidimensionalArray = (base.CreatedType.IsArray && base.UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(this.NonNullableUnderlyingType))
            {
                if (ReflectionUtils.ImplementsGenericDefinition(this.NonNullableUnderlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
                {
                    this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                }
                else
                {
                    this.CollectionItemType = ReflectionUtils.GetCollectionItemType(this.NonNullableUnderlyingType);
                }
                if (this.NonNullableUnderlyingType == typeof(IList))
                {
                    base.CreatedType = typeof(List <object>);
                }
                if (this.CollectionItemType != null)
                {
                    this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(this.NonNullableUnderlyingType, this.CollectionItemType);
                }
                this.IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(this.NonNullableUnderlyingType, typeof(ReadOnlyCollection <>));
                canDeserialize             = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(this.NonNullableUnderlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
            {
                this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(this.NonNullableUnderlyingType, typeof(ICollection <>)) || ReflectionUtils.IsGenericDefinition(this.NonNullableUnderlyingType, typeof(IList <>)))
                {
                    base.CreatedType = typeof(List <>).MakeGenericType(new Type[]
                    {
                        this.CollectionItemType
                    });
                }
                if (ReflectionUtils.IsGenericDefinition(this.NonNullableUnderlyingType, typeof(ISet <>)))
                {
                    base.CreatedType = typeof(HashSet <>).MakeGenericType(new Type[]
                    {
                        this.CollectionItemType
                    });
                }
                this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(this.NonNullableUnderlyingType, this.CollectionItemType);
                canDeserialize           = true;
                this.ShouldCreateWrapper = 1;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(this.NonNullableUnderlyingType, typeof(IEnumerable <>), out type))
            {
                this.CollectionItemType = type.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(base.UnderlyingType, typeof(IEnumerable <>)))
                {
                    base.CreatedType = typeof(List <>).MakeGenericType(new Type[]
                    {
                        this.CollectionItemType
                    });
                }
                this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(this.NonNullableUnderlyingType, this.CollectionItemType);
                this.StoreFSharpListCreatorIfNecessary(this.NonNullableUnderlyingType);
                if (this.NonNullableUnderlyingType.IsGenericType() && this.NonNullableUnderlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    this._genericCollectionDefinitionType = type;
                    this.IsReadOnlyOrFixedSize            = false;
                    this.ShouldCreateWrapper = 0;
                    canDeserialize           = true;
                }
                else
                {
                    this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(new Type[]
                    {
                        this.CollectionItemType
                    });
                    this.IsReadOnlyOrFixedSize = true;
                    this.ShouldCreateWrapper   = 1;
                    canDeserialize             = this.HasParameterizedCreatorInternal;
                }
            }
            else
            {
                canDeserialize           = false;
                this.ShouldCreateWrapper = 1;
            }
            this.CanDeserialize = canDeserialize;
            Type createdType;
            ObjectConstructor <object> parameterizedCreator;

            if (this.CollectionItemType != null && ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(this.NonNullableUnderlyingType, this.CollectionItemType, out createdType, out parameterizedCreator))
            {
                base.CreatedType           = createdType;
                this._parameterizedCreator = parameterizedCreator;
                this.IsReadOnlyOrFixedSize = true;
                this.CanDeserialize        = true;
            }
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonArrayContract"/> class.
        /// </summary>
        /// <param name="underlyingType">The underlying type for the contract.</param>
        public JsonArrayContract(Type underlyingType)
            : base(underlyingType)
        {
            ContractType = JsonContractType.Array;
            IsArray      = CreatedType.IsArray;

            bool canDeserialize;

            Type tempCollectionType;

            if (IsArray)
            {
                CollectionItemType               = ReflectionUtils.GetCollectionItemType(UnderlyingType);
                IsReadOnlyOrFixedSize            = true;
                _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);

                canDeserialize          = true;
                IsMultidimensionalArray = (IsArray && UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(underlyingType))
            {
                if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out _genericCollectionDefinitionType))
                {
                    CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0];
                }
                else
                {
                    CollectionItemType = ReflectionUtils.GetCollectionItemType(underlyingType);
                }

                if (underlyingType == typeof(IList))
                {
                    CreatedType = typeof(List <object>);
                }

                if (CollectionItemType != null)
                {
                    ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
                }

                IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection <>));
                canDeserialize        = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out _genericCollectionDefinitionType))
            {
                CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ICollection <>)) ||
                    ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IList <>)))
                {
                    CreatedType = typeof(List <>).MakeGenericType(CollectionItemType);
                }

                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ISet <>)))
                {
                    CreatedType = typeof(HashSet <>).MakeGenericType(CollectionItemType);
                }

                ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
                canDeserialize          = true;
                ShouldCreateWrapper     = true;
            }
//#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE40)
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>), out tempCollectionType))
            {
                CollectionItemType = underlyingType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>)) ||
                    ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyList <>)))
                {
                    CreatedType = typeof(ReadOnlyCollection <>).MakeGenericType(CollectionItemType);
                }

                _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);
                ParametrizedConstructor          = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, CollectionItemType);
                IsReadOnlyOrFixedSize            = true;
                canDeserialize = (ParametrizedConstructor != null);
            }
//#endif
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable <>), out tempCollectionType))
            {
                CollectionItemType = tempCollectionType.GetGenericArguments()[0];

                if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IEnumerable <>)))
                {
                    CreatedType = typeof(List <>).MakeGenericType(CollectionItemType);
                }

                ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);

                if (underlyingType.IsGenericType() && underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    _genericCollectionDefinitionType = tempCollectionType;

                    IsReadOnlyOrFixedSize = false;
                    ShouldCreateWrapper   = false;
                    canDeserialize        = true;
                }
                else
                {
                    _genericCollectionDefinitionType = typeof(List <>).MakeGenericType(CollectionItemType);

                    IsReadOnlyOrFixedSize = true;
                    ShouldCreateWrapper   = true;
                    canDeserialize        = (ParametrizedConstructor != null);
                }
            }
            else
            {
                // types that implement IEnumerable and nothing else
                canDeserialize      = false;
                ShouldCreateWrapper = true;
            }

            CanDeserialize = canDeserialize;

            if (CollectionItemType != null)
            {
                _isCollectionItemTypeNullableType = ReflectionUtils.IsNullableType(CollectionItemType);
            }

//#if !(NET20 || NET35 || NET40 || PORTABLE40)
            Type       immutableCreatedType;
            MethodBase immutableParameterizedCreator;

            if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, CollectionItemType, out immutableCreatedType, out immutableParameterizedCreator))
            {
                CreatedType             = immutableCreatedType;
                ParametrizedConstructor = immutableParameterizedCreator;
                IsReadOnlyOrFixedSize   = true;
                CanDeserialize          = true;
            }
//#endif
        }
示例#5
0
        public JsonArrayContract(Type underlyingType)
        {
            Class6.yDnXvgqzyB5jw();
            base(underlyingType);
            bool hasParameterizedCreatorInternal;
            Type type;
            Type type1;
            ObjectConstructor <object> objectConstructor;

            this.ContractType = JsonContractType.Array;
            this.IsArray      = base.CreatedType.IsArray;
            if (this.IsArray)
            {
                this.CollectionItemType               = ReflectionUtils.GetCollectionItemType(base.UnderlyingType);
                this.IsReadOnlyOrFixedSize            = true;
                this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                hasParameterizedCreatorInternal       = true;
                this.IsMultidimensionalArray          = (!this.IsArray ? false : base.UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(underlyingType))
            {
                if (!ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
                {
                    this.CollectionItemType = ReflectionUtils.GetCollectionItemType(underlyingType);
                }
                else
                {
                    this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                }
                if (underlyingType == typeof(IList))
                {
                    base.CreatedType = typeof(List <object>);
                }
                if (this.CollectionItemType != null)
                {
                    this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                }
                this.IsReadOnlyOrFixedSize      = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection <>));
                hasParameterizedCreatorInternal = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType))
            {
                this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ICollection <>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IList <>)))
                {
                    base.CreatedType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ISet <>)))
                {
                    base.CreatedType = typeof(HashSet <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                this._parameterizedConstructor  = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                hasParameterizedCreatorInternal = true;
                this.ShouldCreateWrapper        = true;
            }
            else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>), out type))
            {
                this.CollectionItemType = type.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyCollection <>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IReadOnlyList <>)))
                {
                    base.CreatedType = typeof(ReadOnlyCollection <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                this._parameterizedConstructor        = CollectionUtils.ResolveEnumerableCollectionConstructor(base.CreatedType, this.CollectionItemType);
                this.StoreFSharpListCreatorIfNecessary(underlyingType);
                this.IsReadOnlyOrFixedSize      = true;
                hasParameterizedCreatorInternal = this.HasParameterizedCreatorInternal;
            }
            else if (!ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable <>), out type))
            {
                hasParameterizedCreatorInternal = false;
                this.ShouldCreateWrapper        = true;
            }
            else
            {
                this.CollectionItemType = type.GetGenericArguments()[0];
                if (ReflectionUtils.IsGenericDefinition(base.UnderlyingType, typeof(IEnumerable <>)))
                {
                    base.CreatedType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                this._parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, this.CollectionItemType);
                this.StoreFSharpListCreatorIfNecessary(underlyingType);
                if (!underlyingType.IsGenericType() || !(underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                {
                    this._genericCollectionDefinitionType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                    this.IsReadOnlyOrFixedSize            = true;
                    this.ShouldCreateWrapper        = true;
                    hasParameterizedCreatorInternal = this.HasParameterizedCreatorInternal;
                }
                else
                {
                    this._genericCollectionDefinitionType = type;
                    this.IsReadOnlyOrFixedSize            = false;
                    this.ShouldCreateWrapper        = false;
                    hasParameterizedCreatorInternal = true;
                }
            }
            this.CanDeserialize = hasParameterizedCreatorInternal;
            if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, this.CollectionItemType, out type1, out objectConstructor))
            {
                base.CreatedType           = type1;
                this._parameterizedCreator = objectConstructor;
                this.IsReadOnlyOrFixedSize = true;
                this.CanDeserialize        = true;
            }
        }