I am trying to obtain all properties from a class returning constant values through reflection. I have seen this to be working for const fields, obviously, but not for properties.
Is there a way to determine if a property is actually returning a constant value?
Sample:
public class Foo
{
public string Fox => GetSomething(); // should not be returned
public string Foz {get;} // should not be returned
public string Bar {get;set;} // should not be returned
public string Baz => "hello there"; // SHOULD be returned
}
Any effort so far failed. I tried to call GetConstantValue()
on the property, but that throws an exception ("InvalidOperationException: 'Literal value was not found.'"). It doesn't seem to be the right method to do this.