public JsonArrayContract(Type underlyingType) : base(underlyingType) { this.ContractType = JsonContractType.Array; if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection <>), out this._genericCollectionDefinitionType)) { this.CollectionItemType = this._genericCollectionDefinitionType.GetGenericArguments()[0]; } else if (TypeExtensions.IsGenericType(underlyingType) && underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>)) { this._genericCollectionDefinitionType = typeof(IEnumerable <>); this.CollectionItemType = underlyingType.GetGenericArguments()[0]; } else { this.CollectionItemType = ReflectionUtils.GetCollectionItemType(this.UnderlyingType); } if (this.CollectionItemType != null) { this._isCollectionItemTypeNullableType = ReflectionUtils.IsNullableType(this.CollectionItemType); } if (this.IsTypeGenericCollectionInterface(this.UnderlyingType)) { this.CreatedType = ReflectionUtils.MakeGenericType(typeof(List <>), new Type[1] { this.CollectionItemType }); } this.IsMultidimensionalArray = this.UnderlyingType.IsArray && this.UnderlyingType.GetArrayRank() > 1; }
private bool IsTypeGenericDictionaryInterface(Type type) { if (!TypeExtensions.IsGenericType(type)) { return(false); } else { return(type.GetGenericTypeDefinition() == typeof(IDictionary <,>)); } }
private bool IsTypeGenericCollectionInterface(Type type) { if (!TypeExtensions.IsGenericType(type)) { return(false); } Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (genericTypeDefinition != typeof(IList <>) && genericTypeDefinition != typeof(ICollection <>)) { return(genericTypeDefinition == typeof(IEnumerable <>)); } else { return(true); } }