Home > Net >  Attributes of a class name as a parameter to a method, the method based on parameters passed to this
Attributes of a class name as a parameter to a method, the method based on parameters passed to this

Time:12-29

Attributes of a class name as a parameter to a method, the method based on parameters passed to this attribute assignment, how to do?

Such as class
The class claa
{
List P1 {get; set; };
List The p2 {get; set; };
}

Void set pp (aa, string claa p)
{
Aa.?? ,2,2={1};
}

Aa.?? How to directly with parameter p corresponding to pass up, don't use such case method

CodePudding user response:

Can use reflection to obtain aa object attribute name is access to p1, p2

CodePudding user response:

The properties=aa System. Reflection. PropertyInfo []. GetType (). The GetProperties ();
Foreach (System. Reflection. PropertyInfo item in the properties)
{
The object name=item. The name;//the item here. The name is p1 p2 and then you can take the property name to incoming P compared with you
}
I don't know whether you mean it, if I understand is wrong when I didn't say
  •  Tags:  
  • C#
  • Related