public virtual void InitByType(Type type, bool extractGeneric = true) { if (extractGeneric) { type = Store.GetEnumerableGenericType(type); } ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(null, type); if (metadata != null) { var storeModel = this.Model.Primary; if (storeModel == null) { storeModel = new Model(); this.Model.Add(storeModel); } ModelAttribute storeModelAttr = metadata.AdditionalValues.ContainsKey(ModelAttribute.KEY) ? (ModelAttribute)metadata.AdditionalValues[ModelAttribute.KEY] : null; if (storeModelAttr != null) { storeModelAttr.CopyTo(storeModel); } if (metadata.AdditionalValues.ContainsKey(AbstractValidationAttribute.KEY)) { storeModel.Validations.AddRange((ValidationCollection)metadata.AdditionalValues[AbstractValidationAttribute.KEY]); } if (metadata.AdditionalValues.ContainsKey(AbstractAssociationAttribute.KEY)) { storeModel.Associations.AddRange((AssociationCollection)metadata.AdditionalValues[AbstractAssociationAttribute.KEY]); } if (metadata.AdditionalValues.ContainsKey(ProxyAttribute.KEY)) { this.Proxy.Add((AbstractProxy)metadata.AdditionalValues[ProxyAttribute.KEY]); } if (metadata.AdditionalValues.ContainsKey(AbstractReaderAttribute.KEY)) { if (this.Proxy.Primary != null && this.Proxy.Primary is ServerProxy) { ((ServerProxy)this.Proxy.Primary).Reader.Add((AbstractReader)metadata.AdditionalValues[AbstractReaderAttribute.KEY]); } else { this.Reader.Add((AbstractReader)metadata.AdditionalValues[AbstractReaderAttribute.KEY]); } } if (metadata.AdditionalValues.ContainsKey(AbstractWriterAttribute.KEY)) { if (this.Proxy.Primary != null && this.Proxy.Primary is ServerProxy) { ((ServerProxy)this.Proxy.Primary).Writer.Add((AbstractWriter)metadata.AdditionalValues[AbstractWriterAttribute.KEY]); } else { this.Writer.Add((AbstractWriter)metadata.AdditionalValues[AbstractWriterAttribute.KEY]); } } var virtualFieldsAttr = metadata.AdditionalValues.ContainsKey(ModelFieldAttribute.KEY) ? (List <VirtualModelField>)metadata.AdditionalValues[ModelFieldAttribute.KEY] : null; if (virtualFieldsAttr != null) { foreach (VirtualModelField attr in virtualFieldsAttr) { var modelField = new ModelField(); if (storeModel != null) { attr.CopyTo(modelField, storeModel); storeModel.Fields.Add(modelField); } } } var registrator = metadata.AdditionalValues.ContainsKey(ClientResourceAttribute.KEY) ? (ResourcesRegistrator)metadata.AdditionalValues[ClientResourceAttribute.KEY] : null; if (registrator != null) { this.Controls.Add(registrator); } foreach (ModelMetadata propertyMetadata in metadata.Properties) { var modelAttr = propertyMetadata.AdditionalValues.ContainsKey(ModelFieldAttribute.KEY) ? (ModelFieldAttribute)propertyMetadata.AdditionalValues[ModelFieldAttribute.KEY] : null; if (modelAttr == null && this.InitForModelOnly) { continue; } if (modelAttr != null && modelAttr.Ignore) { continue; } Store.CreateModelFieldFromMeta(propertyMetadata, storeModel, modelAttr, this.ControllerContext); } } }