Here is sample code
public class Foo
{
public string Data { get; set; } = "Example";
}
how can I get the default value "Example" of property Data
from typeof(Foo)
? we don't instance the class, don't change class.
there are thousands of all classes, which are from another engineering team, we cannot do any change to those code.
I tried to find a solution from this post: C# Get property value without creating instance? but no luck.
From above post,
- By Jon Skeet's answer, it throw exception at
ugly()
oropenDelegate(null)
, see the screenshot; - By Jordão's answer, it need
attribute
; - By Jon Senchyna & alexm's answer, it need change property to
static
;