Home > Net >  To request a reflection
To request a reflection

Time:09-15

Bits, please give me A problem, now I have A and class B, B is A subclass of, now want to all of the fields under the reflection and get B,
But when get B access field, where there is a problem,

 
Public class A
{
Public B B=new B ();
}
Public class B
{
Public string message1="";
Public string message2="";
}

Var t=typeof (A);
Var m=t.G etMembers ();
M. ll (member=& gt;
{
If (member. The Name. The ToUpper ()=="B")
{
Var fd=member. GetType ();
Fd. The GetFields ()
All (f=& gt;
{
If (motor ame. The Contains (" message1 "))
{
Console. WriteLine (" message1 ");
}
return true;
});
}
return true;
});

CodePudding user response:

Subclasses must mean should not B should inherit A? I am in you didn't see this inheritance
  •  Tags:  
  • C#
  • Related