public void MissingAttributeException_InitTest()
        {
            var expected_attributetype       = new SqlColumnAttribute().GetType();
            var missingAttributeException    = new MissingAttributeException(expected_attributetype);
            var actual_attributeTypeExpected = missingAttributeException.AttributeTypeExpected;

            Assert.Equal(expected_attributetype, actual_attributeTypeExpected);
        }
示例#2
0
        public static string GetAttrProValue(PropertyInfo pro, string attrProName)
        {
            object[] attrArray = pro.GetCustomAttributes(false);
            if (attrArray == null || attrArray.Length == 0)
            {
                return("");
            }

            SqlColumnAttribute attr         = attrArray.First() as SqlColumnAttribute;
            object             attrProValue = attr.GetType().GetProperty(attrProName).GetValue(attr, null) ?? "";

            return(attrProValue.ToString());
        }
示例#3
0
        public static DbColumnInfo BuildInstanceForPropertyInfo(PropertyInfo pi)
        {
            DbColumnInfo dci = new DbColumnInfo();

            dci.PropertyName = pi.Name;
            dci.SetMethod    = pi.SetMethod;
            dci.GetMethod    = pi.GetGetMethod();
            dci.Type         = pi.PropertyType;
            SqlColumnAttribute colattr = (SqlColumnAttribute)pi.GetCustomAttribute(typeof(SqlColumnAttribute));

            if (colattr != null)
            {
                dci.ColumnName = colattr.ColumnName;
            }
            return(dci);
        }
示例#4
0
        private EntityColumnSchema CreateSchema(Type type)
        {
            List <ColumnSchema> columns = new List <ColumnSchema>();

            foreach (PropertyInfo property in type.GetProperties())
            {
                if (property.GetCustomAttribute <NotSqlColumnAttribute>() is null)
                {
                    SqlColumnAttribute sqlColumn =
                        property.GetCustomAttribute <SqlColumnAttribute>();

                    string name = sqlColumn is null ? property.Name : sqlColumn.Name;

                    columns.Add(new ColumnSchema(name, property));
                }
            }

            return(new EntityColumnSchema(type, columns));
        }