mercredi 3 août 2016

Try to hide nameof in function

I would like to be able to pass any possible nameof argument as function parameter.

void A<T>(T smth)
{
   Console.Writeline(nameof(T)); // example usage
}

Now, there is problem with passing property eg.

class Foo
{
    public int Bar { get; set; }
}

I'm able to use: nameof(Foo.Bar) but I'm unable to do A(Foo.Bar)

Is there any possibility to pass property through function to nameof? I would like to hide converting of property to string inside of my class instead of getting ready string. How achieve that?





Aucun commentaire:

Enregistrer un commentaire