사용자 정의 속성을 만들고 Core.dll에 저장했습니다.PropertyInfo 다른 DLL의 GetCustomAtributes
public class DBColumnReference : Attribute
{
string m_column;
public string ColumnName {
get { return m_column; }
}
public DBColumnReference(string column)
{
m_column = column;
}
}
그럼 Core.dll을 참조하는 앱을 만들었습니다.
내 응용 프로그램에서 자신의 개체를 만들고 일부 속성에서 Core.dll의 사용자 지정 특성을 사용합니다.
public class TestingObject4
{
string m_table = "TESTING_CORE_OBJECT4";
public string Table
{
get { return m_table; }
}
private int m_id = 0;
[DBColumnReference("ID")]
public int Id
{
get { return m_id; }
set { m_id = value; }
}
는 I 핵심 방법 "FilterProperties (대해서 typeof (TestingObject4))"속성에 의해 필터 특성을 호출한다.
private static Dictionary<string, PropertyInfo> FilterProperties(Type type)
{
Dictionary<string, PropertyInfo> result = new Dictionary<string, PropertyInfo>();
if(type == null)
return result;
PropertyInfo[] properties = type.GetProperties();
foreach(PropertyInfo prop in properties)
{
// Attribute[] atributes = Attribute.GetCustomAttributes(prop, true);
object[] atributes = prop.GetCustomAttributes(typeof(DBColumnReference), true);
if(atributes != null && atributes.Length != 0)
{
DBColumnReference reference = atributes[0] as DBColumnReference;
result.Add(reference.ColumnName, prop);
}
}
return result;
}
그리고 Attributes[]
속성은 항상 비어 있습니다. 속성을 올바르게 가져 오는 방법은 무엇입니까?
당신이에서 속성을 얻고있는 유형을 게시 할 수 있을까요? – Xharze
질문에 추가되었습니다. –
타입 ('object [] atributes = prop.GetCustomAttributes (true);')을 제공하지 않고'GetCustomAttributes()'를 시도해보고 어떻게 될까요? –