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); }
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)); }
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)); }
private static string GetColumnName(MemberInfo member) { return(FieldDefintionAttribute.ClassFieldName(member.DeclaringType, member.Name) ?? member.Name); }