Using reflection I want to retrieve only the properties that have both a get and a set method, and ignore ones with only a get. What I’m trying to do is give the user a list of variables that he/she is able to change, so showing them properties that only have a get method is misleading.
Given this code below, the user would only be shown Name. Or I could possibly show them both, but grey-out UniqueID so they know they cannot change it.
public Int64 UniqueID
{
get { return this.uniqueID; }
}
public String Name
{
get { return this.name; }
set { this.name = value; }
}
Background Info: I’m using C# 4.0.
You can use the
CanReadandCanWriteproperties:Do note that the above query looks only for public properties with public accessors.