Esempio n. 1
0
        //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);
        }
Esempio n. 2
0
        RelationFieldConfig LoadRelationFieldConfig(XmlNode fieldNode, Type dataType)
        {
            if (fieldNode == null)
            {
                throw new ArgumentException("FieldNode");
            }
            if (dataType == null)
            {
                throw new ArgumentException("IgnoraField");
            }
            if (fieldNode.Name != "RelationField")
            {
                throw new LightDataException(string.Format(RE.ConfigDataLoadError, "RelationField"));
            }
            RelationFieldConfig config = null;
            string fieldName           = null;

            if (fieldNode.Attributes["FieldName"] != null)
            {
                fieldName = fieldNode.Attributes["FieldName"].Value;
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new LightDataException(string.Format(RE.ConfigDataFieldNameIsEmpty, dataType.Name));
            }
            PropertyInfo property = dataType.GetProperty(fieldName);

            if (property == null)
            {
                throw new LightDataException(string.Format(RE.ConfigDataFieldNameIsEmpty, dataType.Name, fieldName));
            }
            config = new RelationFieldConfig(fieldName);
            if (fieldNode.Attributes["Property"] != null)
            {
                config.PropertyName = fieldNode.Attributes["Property"].Value;
            }
            foreach (XmlNode keyNode in fieldNode.ChildNodes)
            {
                if (keyNode.Name == "RelationKey")
                {
                    string masterKey = null;
                    string relateKey = null;
                    if (keyNode.Attributes["MasterKey"] != null)
                    {
                        masterKey = keyNode.Attributes["MasterKey"].Value;
                    }
                    else
                    {
                        throw new LightDataException(string.Format(RE.ConfigDataLoadError, "MasterKey"));
                    }
                    if (keyNode.Attributes["RelateKey"] != null)
                    {
                        relateKey = keyNode.Attributes["RelateKey"].Value;
                    }
                    else
                    {
                        throw new LightDataException(string.Format(RE.ConfigDataLoadError, "RelateKey"));
                    }
                    config.AddRelationKeys(masterKey, relateKey);
                }
            }
            return(config);
        }