简体   繁体   中英

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.

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

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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