2つのクラスが互いにメンバーとして追加されていることを確認する方法を教えてください。私は、プロパティを取得するには、次の方法を使用していた.NETリフレクション - チェック2クラスが互いにメンバーとして追加されます
class Team
{
Driver driver{ get; set;}
Driver codriver{ get; set;}
}
class Driver
{
Team parentTeam{ get; set;}
}
: -
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (PropertyInfo property in properties)
{
////if (!isParent) //need to find this.
//{
object propertyValue = property.GetValue(obj);
if (propertyValue != null)
{
// Get the deep clone of the field in the original object and assign the clone to the field in the new object.
property.SetValue(copiedObject, CloneProcedure(propertyValue));
}
//}
}
私は第二1を反復する際秒でプロパティはファーストクラスをスキップします。 注:私のクラスは間違って宣言されていると感じるかもしれませんが、これはレガシーシステムであり、クラスを再構築する機会はありません。
私はDeclaringTypeを試しましたが、私はproperty.DeclaringTypeを取得しましたが、obj.GetType()を取得しました。DeclaringTypeはnullです。
'メソッドGetType()をDelcaringType'は、ネストされたタイプです –
ない「親/子」はありませんここでの関係。私はそれらの用語を使用することは疑問を混乱させると思います。 (さらに、空間表現 "back in the child object。")あなたが2つのタイプを使って何をしたいのかを言い換えるだけで言い換えると、より明確になるかもしれません。 –
'BindingFlags.DeclaredOnly'を試しましたか? – thehennyy