示例#1
0
        public void TestFieldNameAttribute()
        {
            var results = FieldDefintionAttribute.ClassFieldName(typeof(DbClassLibrary.ActiveRecords.Employee), "NameLast");

            Assert.IsNotEmpty(results);
            Assert.IsNull(FieldDefintionAttribute.ClassFieldName(typeof(DbClassLibrary.ActiveRecords.Employee), "Ssn"));
            Console.WriteLine(results);
        }
示例#2
0
 protected override Expression VisitMemberAccess(MemberExpression m)
 {
     if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
     {
         _sb.Append(FieldDefintionAttribute.ClassFieldName(m.Member.DeclaringType, m.Member.Name) ?? m.Member.Name);
         return(m);
     }
     throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
 }
示例#3
0
        public void TestFieldInfo()
        {
            var hostType = typeof(DbClassLibrary.ActiveRecords.Employee);

            var results = from t in (from p in hostType.GetProperties() select p)
                          from a in t.GetCustomAttributes(true)
                          where a is FieldDefintionAttribute
                          select FieldDefintionAttribute.ClassFieldName(hostType, t.Name) ?? t.Name;

            foreach (var field in results)
            {
                Console.WriteLine(field);
            }

            Assert.IsTrue(typeof(ActiveRecord).IsAssignableFrom(hostType));
        }
示例#4
0
 private static string GetColumnName(MemberInfo member)
 {
     return(FieldDefintionAttribute.ClassFieldName(member.DeclaringType, member.Name) ?? member.Name);
 }