I was wondering if it is possible to declare an Attribute property that describes the property, so strong typing is required and ideally what intellisense can use to select the property. Class types work fine by declaring a member as Type Type. But how to get a property as a parameter so that "PropName" is not quoted and strongly typed?
So far: the Attibute class and sample usage look like
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class MyMeta : Attribute{ public Type SomeType { get; set; }
EDIT: To avoid using property name strings, I built a simple tool that allows you to save compile-time checks during storage and use property names in places as strings.
The idea is that you quickly reference a property through its type and name using intellisense help and code completion from a similar resharper. However, pass STRING to the tool.
I use a resharper template with this code shell string propname = Utilites.PropNameAsExpr( (SomeType p) => p.SomeProperty )
which refers to
public class Utilities{ public static string PropNameAsExpr<TPoco, TProp>(Expression<Func<TPoco, TProp>> prop) {
c # custom-attributes
phil soady
source share