我有這樣定義的類:如何知道一個類的屬性的類型是定製
public class Company
{
public Int32 OrganisationID {get;set;}
public CompanyStatus OrganisationStatus {get;set;}
// note that CompanyStatus is my custom type
}
然後我將代碼編譯成Entity.dll
。當我使用下面的代碼時,我得到((System.Reflection.MemberInfo)(properties[1])).Name
爲CompanyStatus
。我如何判斷它是否爲自定義類型,因爲我正在動態讀取所有屬性?
Assembly objAssembly = Assembly.LoadFrom(@"Entities.dll");
var types1 = objAssembly.GetTypes();
foreach (Type type in types1)
{
string name = type.Name;
var properties = type.GetProperties(); // public properties
foreach (PropertyInfo objprop in properties)
{
// Code here
}
}
你是什麼意思「自定義類型」?你的意思是,如果它是BCL(基類庫)的一部分 – Tigran
@Tigran我想捕獲除原始類型以外的其他東西。如果我有屬性列表我想提取類型即CustomTypeA –