How to find out if a property is an auto-implemented property with reflection?

You could check to see if the get or set method is marked with the CompilerGenerated attribute. You could then combine that with looking for a private field that is marked with the CompilerGenerated attribute containing the name of the property and the string “BackingField”. Perhaps: public static bool MightBeCouldBeMaybeAutoGeneratedInstanceProperty( this PropertyInfo info ) { … Read more

What are Automatic Properties in C# and what is their purpose?

Automatic Properties are used when no additional logic is required in the property accessors. The declaration would look something like this: public int SomeProperty { get; set; } They are just syntactic sugar so you won’t need to write the following more lengthy code: private int _someField; public int SomeProperty { get { return _someField;} … Read more

Public Fields versus Automatic Properties

In a related question I had some time ago, there was a link to a posting on Jeff’s blog, explaining some differences. Properties vs. Public Variables Reflection works differently on variables vs. properties, so if you rely on reflection, it’s easier to use all properties. You can’t databind against a variable. Changing a variable to … Read more

tech