假设我有一个名为 Test 的类,它有一个名为 Title 的属性和一个自定义属性:
public class Test
{
[DatabaseField("title")]
public string Title { get; set; }
}
以及一个名为 DbField 的扩展方法。我想知道在 c# 中是否可以从对象实例中获取自定义属性。
Test t = new Test();
string fieldName = t.Title.DbField();
//fieldName will equal "title", the same name passed into the attribute above
这可以做到吗?