internal static IDataFieldConfig LoadDataFieldConfig(PropertyInfo pi) { IDataFieldConfig config = null; if (config == null) { LightDataConfig lightDataConfig = GetConfig(); if (lightDataConfig != null && lightDataConfig.ContainDataTableConfig(pi.ReflectedType)) { DataTableConfig dtconfig = lightDataConfig.GetDataTableConfig(pi.ReflectedType); IConfiguratorFieldConfig fieldConfig = dtconfig[pi.Name]; if (fieldConfig != null) { if (fieldConfig is IgnoraFieldConfig) { return(null); } config = dtconfig[pi.Name] as DataFieldConfig; } } } if (config == null) { DataFieldAttribute[] attributes = AttributeCore.GetPropertyAttributes <DataFieldAttribute>(pi, true); if (attributes.Length > 0) { config = attributes[0]; } } return(config); }
DataTableConfig LoadDataTableConfig(XmlNode typeNode) { if (typeNode == null) { throw new ArgumentException("TypeNode"); } if (typeNode.Name != "DataType") { throw new LightDataException(string.Format(RE.ConfigDataLoadError, "DataType")); } DataTableConfig config = null; Type dataType = null; string typeName = null; if (typeNode.Attributes["Type"] != null) { typeName = typeNode.Attributes["Type"].Value; } if (string.IsNullOrEmpty(typeName)) { throw new LightDataException(string.Format(RE.ConfigDataTypeValueIsEmpty, "Type")); } dataType = System.Type.GetType(typeName, true); config = new DataTableConfig(dataType); if (typeNode.Attributes["TableName"] != null) { config.TableName = typeNode.Attributes["TableName"].Value; } if (typeNode.Attributes["ExtendParams"] != null) { config.ExtendParams = typeNode.Attributes["ExtendParams"].Value; } if (typeNode.Attributes["IsEntityTable"] != null) { config.IsEntityTable = Convert.ToBoolean(typeNode.Attributes["IsEntityTable"].Value); } foreach (XmlNode fieldNode in typeNode.ChildNodes) { IConfiguratorFieldConfig fieldConfig = null; if (fieldNode.Name == "DataField") { fieldConfig = LoadDataFieldConfig(fieldNode, dataType); } else if (fieldNode.Name == "IgnoraField") { fieldConfig = LoadIgnoraFieldConfig(fieldNode, dataType); } else if (fieldNode.Name == "RelationField") { fieldConfig = LoadRelationFieldConfig(fieldNode, dataType); } if (fieldConfig != null) { config.SetField(fieldConfig); } } return(config); }
//internal static IRelationConfig[] LoadRelationConfigs(PropertyInfo pi) //{ // IRelationConfig[] configs = null; // RelationAttribute[] attributes = AttributeCore.GetPropertyAttributes<RelationAttribute>(pi, true); // if (attributes.Length > 0) // { // configs = attributes; // } // return configs; //} //internal static IRelationPropertyConfig LoadRelationPropertyConfig(PropertyInfo pi) //{ // IRelationPropertyConfig config = null; // RelationPropertyAttribute[] attributes = AttributeCore.GetPropertyAttributes<RelationPropertyAttribute>(pi, true); // if (attributes.Length > 0) // { // config = attributes[0]; // } // return config; //} internal static IRelationFieldConfig LoadRelationFieldConfig(PropertyInfo pi) { IRelationFieldConfig config = null; if (config == null) { LightDataConfig lightDataConfig = GetConfig(); if (lightDataConfig != null && lightDataConfig.ContainDataTableConfig(pi.ReflectedType)) { DataTableConfig dtconfig = lightDataConfig.GetDataTableConfig(pi.ReflectedType); IConfiguratorFieldConfig fieldConfig = dtconfig[pi.Name]; if (fieldConfig != null) { if (fieldConfig is IgnoraFieldConfig) { return(null); } config = dtconfig[pi.Name] as RelationFieldConfig; } } } if (config == null) { RelationAttribute[] relationAttributes = AttributeCore.GetPropertyAttributes <RelationAttribute>(pi, true); if (relationAttributes.Length > 0) { RelationFieldConfig rfConfig = new RelationFieldConfig(pi.Name); foreach (RelationAttribute ra in relationAttributes) { rfConfig.AddRelationKeys(ra.MasterKey, ra.RelateKey); } RelationPropertyAttribute[] relationPropertyAttributes = AttributeCore.GetPropertyAttributes <RelationPropertyAttribute>(pi, true); if (relationPropertyAttributes.Length > 0) { rfConfig.PropertyName = relationPropertyAttributes[0].PropertyName; } config = rfConfig; } } return(config); }
AggregateTableConfig LoadAggregateTableConfig(XmlNode typeNode) { if (typeNode == null) { throw new ArgumentException("TypeNode"); } if (typeNode.Name != "AggregateType") { throw new LightDataException(string.Format(RE.ConfigDataLoadError, "AggregateType")); } AggregateTableConfig config = null; Type dataType = null; Type relateType = null; string dataTypeName = null; string relateTypeName = null; if (typeNode.Attributes["Type"] != null) { dataTypeName = typeNode.Attributes["Type"].Value; } if (string.IsNullOrEmpty(dataTypeName)) { throw new LightDataException(string.Format(RE.ConfigDataTypeValueIsEmpty, "Type")); } if (typeNode.Attributes["RelateType"] != null) { relateTypeName = typeNode.Attributes["RelateType"].Value; } //if (string.IsNullOrEmpty(relateTypeName)) //{ // throw new LightDataException(string.Format(RE.ConfigDataTypeValueIsEmpty, "RelateType")); //} dataType = System.Type.GetType(dataTypeName, true); if (!string.IsNullOrEmpty(relateTypeName)) { relateType = System.Type.GetType(relateTypeName, true); } config = new AggregateTableConfig(dataType, relateType); if (typeNode.Attributes["ExtendParams"] != null) { config.ExtendParams = typeNode.Attributes["ExtendParams"].Value; } foreach (XmlNode fieldNode in typeNode.ChildNodes) { IConfiguratorFieldConfig fieldConfig = null; if (fieldNode.Name == "AggregateField") { fieldConfig = LoadAggregateFieldConfig(fieldNode, dataType); } if (fieldNode.Name == "IgnoraField") { fieldConfig = LoadIgnoraFieldConfig(fieldNode, dataType); } if (fieldConfig != null) { config.SetField(fieldConfig); } } return(config); }