示例#1
0
        /// <summary>
        /// 根据实体类中自定义属性主键标识名称、值信息--create by guochao
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        public EntityColumn GetIdColumn <T>(object Id)
        {
            EntityColumn column = null;
            Type         type   = typeof(T);

            PropertyInfo[] props = type.GetProperties();
            if (props.Length > 0)
            {
                foreach (PropertyInfo proInfo in props)
                {
                    object[] selftDefineAttrs = proInfo.GetCustomAttributes(typeof(EntityColumnAttribute), true);
                    if (selftDefineAttrs.Length > 0)
                    {
                        EntityColumnAttribute selftDefineAttr = (EntityColumnAttribute)selftDefineAttrs[0];
                        if (selftDefineAttr.IsPk)
                        {
                            column = new EntityColumn();
                            if (Id == null)
                            {
                                Id = DBNull.Value;
                            }
                            column.ColumnName         = selftDefineAttr.FieldName;
                            column.ColumnValue        = Id;
                            column.IsPk               = selftDefineAttr.IsPk;
                            column.IsIdentity         = selftDefineAttr.IsIdentity;
                            column.IsGetIdentityValue = selftDefineAttr.IsGetIdentityValue;
                            break;
                        }
                    }
                }
            }
            return(column);
        }
示例#2
0
        /// <summary>
        /// 获取单个自定义列名和值信息--create by guochao
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="t"></param>
        /// <param name="proInfo"></param>
        /// <returns></returns>
        private EntityColumn GetSelftDefineProperInfo <T>(Type type, T t, PropertyInfo proInfo)
        {
            EntityColumn column = null;

            if (proInfo != null)
            {
                object[] selftDefineAttrs = proInfo.GetCustomAttributes(typeof(EntityColumnAttribute), true);
                if (selftDefineAttrs.Length > 0)
                {
                    column = new EntityColumn();
                    EntityColumnAttribute selftDefineAttr = (EntityColumnAttribute)selftDefineAttrs[0];
                    object selftDefineAttrVal             = type.GetProperty(selftDefineAttr.FieldName).GetValue(t, null);
                    if (selftDefineAttrVal == null)
                    {
                        selftDefineAttrVal = DBNull.Value;
                    }
                    column.ColumnName         = selftDefineAttr.FieldName;
                    column.ColumnValue        = selftDefineAttrVal;
                    column.IsPk               = selftDefineAttr.IsPk;
                    column.IsIdentity         = selftDefineAttr.IsIdentity;
                    column.IsGetIdentityValue = selftDefineAttr.IsGetIdentityValue;
                }
            }
            return(column);
        }