dimanche 10 décembre 2017

About MethodInfo Invoke exception

I have one C# clause "DateTime.Now.AddDays(1)"

Now I want to analysis that clause and invoke that AddDays method by reflection as below:

var parameters = new List<object>();
            if (mce.Arguments.Any())
            {
                parameters = mce.Arguments.Select(arg => Convert.ChangeType(DealExpress(arg, false), arg.Type)).ToList();
            }
            var res = mce.Method.Invoke(mce.Object, parameters.ToArray());

But I got an exception about "Exception thrown: 'System.Reflection.TargetException' in mscorlib.dll Additional information: The object does not match the target type。"





Aucun commentaire:

Enregistrer un commentaire