Home > Net >  C # reflection set Boolean value is not successful
C # reflection set Boolean value is not successful

Time:11-10

This is the normal operation, didn't also encountered similar problems before,
 
Type Type=typeof (JiChuKu);
Var Properties=the GetProperties ();

Var des=the GetProperty (" attribute name ");

Des. SetValue (jckCurrentKong, attribute values, null);



Met today,
If the attribute value is a string, value, the above code no problem;
But if the attribute value is a bool type, how to also pass ah,

Try the following methods are not
 des. SetValue (jckCurrentKong, false. The ToString (), null); 

 des. SetValue (jckCurrentKong, "false", null); 

 des. SetValue (jckCurrentKong, 0, null); 



Please solve the
There is another problem, very confused, so simple of a problem, baidu search for nearly two hours, just didn't find similar questions...

CodePudding user response:

Value directly with false/true

CodePudding user response:

Des. SetValue (jckCurrentKong, false, null); Have a try

CodePudding user response:

 
System. Reflection. PropertyInfo info=the GetProperty (key);
Info. SetValue (obj, false, null);
  •  Tags:  
  • C#
  • Related