ネストされたオブジェクトのプロパティを取得できません。私が働いています例えば、私は2クラスありますが、十分なシンプルC#Reflection:ネストされたオブジェクトのプロパティを取得する
public class user
{
public int _user_id {get; set;}
public string name {get; set;}
public category {get; set;}
}
public class category
{
public int category_id {get; set;}
public string name {get; set;}
}
を、と私はそれらのいずれかを反映している場合、私ならば、私は、例えば、GetPropertiesの()の適切なセットを取得します次の操作を行います。
PropertyInfo[] props = new user().GetType().GetProperties();
私はプロパティにのuser_id、名とカテゴリを取得し、かつます私はこれを行う場合:
をPropertyInfo[] props = new category().GetType().GetProperties();
私はプロパティCATEGORY_IDとカテゴリを取得します。これはうまく動作します。 しかし、私は混乱ところ、これは私がこれを行う場合
、あなたが見ることができるように、 カテゴリが ユーザーの最後の財産です...ある
//this gets me the Type 'category'
Type type = new user().GetType().GetProperties().Last().PropertyType;
//in the debugger, I get "type {Name='category', FullName='category'}"
//so I assume this is the proper type, but when I run this:
PropertyInfo[] props = type.GetType().GetProperties();
//I get a huge collection of 57 properties
私はすべてのアイデアねじれ?これはできますか?
私は実際に説明を簡単にするために、.Last()を使って実際に調べているわけではありません。 – naspinski
非常に良い。これらの質問は検索エンジンによって索引付けされるので、注文を避ける必要があることを人々が気づくべきだと思うので、コメントをそのまま残しておきます。 – Lucero
うわー、とてもシンプルだ...私はあまりにも難しいと思っていた(または不十分かもしれない)、ありがとう! – naspinski