Of course, it would look similar to the following:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class DataElementAttribute : Attribute
{ }
You will have to enumerate the properties with reflection to see if the property contains the attribute. (which begs the question, do you really need the attribute).
Assembly assembly = Assembly.GetExecutingAssembly();
foreach (Type type in assembly.GetTypes())
{
IList<PropertyInfo> properties = type.GetProperties();
foreach (PropertyInfo pi in properties)
{
if (type.IsDefined(typeof(DataElementAttribute), false))
{
// Perform Logic
}
}
}
However injecting Logic into the setter is a different task which would need to be done post compilation: Why is post-compilation code injection a better idea than pre-compilation code injection?
Injecting MSIL is not easy. Take a peek at this example code: http://www.codeproject.com/Articles/37549/CLR-Injection-Runtime-Method-Replacer