This code will get us all the properties of a class:
Dim myPropertyInfo As PropertyInfo()
= myType.GetProperties((BindingFlags.Public Or BindingFlags.Instance))
or in C#:
PropertyInfo[] myPropertyInfo
= myType.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance);
But is there a way to get just the properties defined as ReadOnly?
Or, equally, to exclude the ReadOnly properties?
Just filter the results to those which have
CanWriteasFalseNote the above code sample is assuming
Visual Studio 2008or higher and requires an import ofSystem.Linq. If you’re using an older version you can do the following