Exemple #1
0
        private static IMemberAttribute GenerateMember(IMemberAttribute member, XmlNode memberNode)
        {
            if (null == memberNode)
            {
                return(member);
            }
            object oFieldName;
            object oAllowNull;
            object oLength;
            object oPrimaryKey;
            object oDbType;
            object oIsSave;

            if (XmlFileParser.TryGetAttributeValue(memberNode, "FieldName", out oFieldName) && null != oFieldName)
            {
                member.FieldName = oFieldName.ToString().Trim();
            }
            if (XmlFileParser.TryGetAttributeValue(memberNode, "AllowNull", out oAllowNull) && null != oAllowNull)
            {
                member.AllowNull = bool.Parse(oAllowNull.ToString().Trim());
            }
            if (XmlFileParser.TryGetAttributeValue(memberNode, "Length", out oLength) && null != oLength)
            {
                member.Length = int.Parse(oLength.ToString().Trim());
            }
            if (XmlFileParser.TryGetAttributeValue(memberNode, "PrimaryKey", out oPrimaryKey) && null != oPrimaryKey)
            {
                member.PrimaryKey = bool.Parse(oPrimaryKey.ToString().Trim());
                if (member.PrimaryKey)
                {
                    member.AllowNull = false;
                }
            }
            if (XmlFileParser.TryGetAttributeValue(memberNode, "DbType", out oDbType) && null != oDbType)
            {
                member.DBType = ConvertToDbType.Convert(oDbType.ToString());
            }
            if (XmlFileParser.TryGetAttributeValue(memberNode, "IsSave", out oIsSave) && null != oIsSave)
            {
                member.IsSave = bool.Parse(oIsSave.ToString().Trim());
            }
            return(member);
        }
Exemple #2
0
        public IMemberAttribute ReflectProperty(PropertyInfo propertyInfo, PropertyInfo idInfo, PropertyInfo isNewInfo)
        {
            object[] attrs = propertyInfo.GetCustomAttributes(typeof(AlbianMemberAttribute), true);

            if (propertyInfo.Name == idInfo.Name)
            {
                if (null == attrs || 0 == attrs.Length)
                {
                    attrs = idInfo.GetCustomAttributes(typeof(AlbianMemberAttribute), true);
                }
                ;
            }
            if (propertyInfo.Name == isNewInfo.Name)
            {
                if (null == attrs || 0 == attrs.Length)
                {
                    attrs = isNewInfo.GetCustomAttributes(typeof(AlbianMemberAttribute), true);
                }
                ;
            }

            IMemberAttribute memberAttribute;

            if (null == attrs || 0 == attrs.Length)
            {
                memberAttribute = new AlbianMemberAttribute
                {
                    Name       = propertyInfo.Name,
                    PrimaryKey = false,
                    FieldName  = propertyInfo.Name,
                    DBType     = ConvertToDbType.Convert(propertyInfo.PropertyType),
                    IsSave     = true,
                    AllowNull  = Utils.IsNullableType(propertyInfo.PropertyType)
                };
            }
            else
            {
                AlbianMemberAttribute attr = (AlbianMemberAttribute)attrs[0];
                memberAttribute = new AlbianMemberAttribute();
                if (string.IsNullOrEmpty(attr.FieldName))
                {
                    memberAttribute.FieldName = propertyInfo.Name;
                }
                if (string.IsNullOrEmpty(attr.Name))
                {
                    memberAttribute.Name = propertyInfo.Name;
                }

                //it have problem possible
                memberAttribute.AllowNull = attr.AllowNull
                                                ? Utils.IsNullableType(propertyInfo.PropertyType) ? true : false
                                                : false;
                memberAttribute.DBType = DbType.Object == attr.DBType
                                             ? ConvertToDbType.Convert(propertyInfo.PropertyType)
                                             : attr.DBType;
                memberAttribute.IsSave     = attr.IsSave;
                memberAttribute.Length     = attr.Length;
                memberAttribute.PrimaryKey = attr.PrimaryKey;
            }
            return(memberAttribute);
        }