If you are stuck or confused with any of the code in the example, just release the comment and I will try to help.
In general, you are interested in using Reflection to traverse type metadata to get properties that are assigned a given attribute.
Below is just one way to do this (there are many others, as well as many methods that provide similar functionality).
Taken from this question I contacted in the comments:
PropertyInfo[] properties = viewModelInstance.GetType().GetProperties(); foreach (PropertyInfo property in properties) { var attribute = Attribute.GetCustomAttribute(property, typeof(KeyAttribute)) as KeyAttribute; if (attribute != null)
As John says, process multiple KeyAttribute declarations to avoid problems. This code also assumes that you are decorating public properties (non, non-public properties or fields) and require System.Reflection .
source share