1

Is it possible to get the name of class's property (attention!) at compile time and without object instantiation?
With instantiation it can easely be done with nameof():

class DummyClass
{
    public int DummyProperty { get; set; }
}
void Meth()
{
    //With instantiation
    var dc = new DummyClass();
    var prname = nameof(dc.DummyProperty);
}
Rekshino
  • 6,954
  • 2
  • 19
  • 44

1 Answers1

3

You may use nameof(DummyClass.DummyProperty), if I understood you correctly.

There is a similar example for such a use case at docs.

Used to obtain the simple (unqualified) string name of a variable, type, or member.

Uladzislaŭ
  • 1,680
  • 10
  • 13