public static DependencyProperty GetTextualProperty <T>(TextualRole role) where T : TextualPrimitive { var fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static); foreach (var dependencyProperty in from field in fields let attributes = field.GetCustomAttributes() from attribute in attributes let dependencyProperty = field.GetValue(null) as DependencyProperty where dependencyProperty != null let textualRoleProperty = attribute as TextualRolePropertyAttribute where textualRoleProperty?.Role == role select dependencyProperty) { return(dependencyProperty); } throw new Exception("cant find textualrole property"); }
public TextualRolePropertyAttribute(TextualRole role) { Role = role; }