dimanche 4 août 2019

Passing Nullable Int using reflection C#

i am using the following logging proxy in my code:

https://www.codeproject.com/Articles/1219720/Aspect-Oriented-Programming-in-Csharp-using-Dispat

the most important thing about it, is this line of code

var result = targetMethod.Invoke(_decorated, args);


the target method has 3 parameters, one of them is nullable integer as the following

public int targetMethod(string name, int number, int? count)

the args that is getting passed to Invoke method has the following values as you can view it in the visual studio debugging mode:

["nadeem", 123, (null)]

the invoke is raising an exception that i cannot convert string to nullable integer.

how i can avoid this type of issue, note that i am not sure which function i am going to be invoked, i would only know it on runtime.

thanks





Aucun commentaire:

Enregistrer un commentaire