samedi 22 juin 2019

Get both name and type of a single passed argument?

I need to write a method that takes both the name and the type of a passed argument. For example, a call might look like this:

MyMethod( nameof(MyVar), MyVar.GetType() );

Is there any way to simplify this call so that I pass only one argument instead of two, but the method can still figure out both the name and type of that passed argument? The only way I know is by creating a macro and running the source through a pre-build external C# preprocessor. Then the call could look something like:

MyMethod( MyVar );

...but I want to avoid using a preprocessor.





Aucun commentaire:

Enregistrer un commentaire