/// <summary> /// Creates a type descriptor for the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>An instance of type descriptor.</returns> protected virtual ITypeDescriptor Create(Type type) { ObjectDescriptor descriptor; // The order of the descriptors here is important if (PrimitiveDescriptor.IsPrimitive(type)) { descriptor = new PrimitiveDescriptor(attributeRegistry, type, namingConvention); } else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections { // IDictionary descriptor = new DictionaryDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention); } else if (CollectionDescriptor.IsCollection(type)) { // ICollection descriptor = new CollectionDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention); } else if (type.IsArray) { // array[] descriptor = new ArrayDescriptor(attributeRegistry, type, namingConvention); } else if (NullableDescriptor.IsNullable(type)) { descriptor = new NullableDescriptor(attributeRegistry, type, namingConvention); } else { // standard object (class or value type) descriptor = new ObjectDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention); } // Initialize the descriptor descriptor.Initialize(); return(descriptor); }
/// <summary> /// Creates a type descriptor for the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>An instance of type descriptor.</returns> protected virtual ITypeDescriptor Create(Type type) { ITypeDescriptor descriptor; // The order of the descriptors here is important if (PrimitiveDescriptor.IsPrimitive(type)) { descriptor = new PrimitiveDescriptor(attributeRegistry, type); } else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections { // IDictionary descriptor = new DictionaryDescriptor(attributeRegistry, type, emitDefaultValues); } else if (CollectionDescriptor.IsCollection(type)) { // ICollection descriptor = new CollectionDescriptor(attributeRegistry, type, emitDefaultValues); } else if (type.IsArray) { // array[] descriptor = new ArrayDescriptor(attributeRegistry, type); } else if (NullableDescriptor.IsNullable(type)) { descriptor = new NullableDescriptor(attributeRegistry, type); } else { // standard object (class or value type) descriptor = new ObjectDescriptor(attributeRegistry, type, emitDefaultValues); } return descriptor; }