mardi 1 décembre 2015

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"





Aucun commentaire:

Enregistrer un commentaire