Checking readonly property using reflection?
-
Hi I am using reflection to write properties in some code. But, I don't need to fetch readonly properties. How can I check whether a property is readonly or not in .NET? Please advise. Thanks Pankaj
-
Hi I am using reflection to write properties in some code. But, I don't need to fetch readonly properties. How can I check whether a property is readonly or not in .NET? Please advise. Thanks Pankaj
You can use the second line specifying the
BindingFlags
with aSetProperty
which excludes all properties that don't include aset
declaration on the property.static IEnumerable<PropertyInfo> GetWritableProperties<T>()
{
Type type = typeof(T);
return type.GetProperties(BindingFlags.SetProperty);
}
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder