2016-07-13 17 views

答えて

2

var obj = new MyClass(); 

foreach (var prop in obj.GetType().GetProperties()) 
{ 
    Console.WriteLine($"Name = {prop.Name} ** Type = { prop.PropertyType}"); 
} 

結果:

Name = List ** Type = System.Collections.Generic.List`1[NameSpaceSample.SomeObj] 
Name = SomeKey ** Type = System.Int32 
Name = SomeString ** Type = System.String 

あなたがよりユーザーフレンドリー型の名前を探しているなら、thisを参照してください。次いで、特定のタイプのプロパティ持っとして

bool hasInt = obj.GetType().GetProperties().Any(prop => prop.PropertyType == typeof(int)); 
関連する問題