简体   繁体   English

无法使用反射设置属性

[英]Failed to set property using reflection

I'm creating a dynamic class and using reflection to assign the property values, the class has two properties 我正在创建一个动态类,并使用反射来分配属性值,该类具有两个属性

public int Tipo_Pension {set;get;}
public bool Novedad_TDP {set;get;}

And I use the following code to set the values. 我使用以下代码设置值。 VariableName is the name of the property and Value the real value of the property to set, and ruleMeta.Evaluator is the binder. VariableName是属性的名称,Value是要设置的属性的实际值,ruleMeta.Evaluator是活页夹。

private void SetVariable(string VariableName, object Value, RuleMeta ruleMeta)
{
    o = ruleMeta.EvaluatorType.InvokeMember(
        VariableName,
        BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty,
        Type.DefaultBinder,
        ruleMeta.Evaluator,
        new object[] { Value }
    );
}

The fist property, the Integer, works fine, but when its executed for the Boolean it fails and throws the next error fist属性Integer可以正常工作,但是对布尔值执行时,它会失败并引发下一个错误

Method 'Cenet.RulesManager.Rule360788846.Novedad_TDP' not found

Any idea what could be happening? 知道会发生什么吗?

Note: the object Value for the Boolean comes as a string: "false" 注意:布尔值的对象Value以字符串形式出现:“ false”

正如M.kazem Akhgary所说,我正在用一个字符串设置布尔值,就这么简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM