This may well not be possible, but if it is possible it will save me a great deal of time in a large project.
Let's say I have an extension method to format a string. The implementation of the extension method isn't important, but imagine it is this:
public static string AddPrefix(this string input) {
return string.Format("{0}{1}", "pre_", input);
}
What I would love to be able to do it add a data annotation to a field in my model that I want the extension method to be applied to. I don't want to validate user input to match the format of the extension method, but I want to apply the extension method before submitting the data for any field it would apply to.
For instance, I might have:
public class Person {
[Prefix]
public string Forename {get;set;}
}
I would then want to apply the extension method to the forename before submitting the model to a database or webservice.
I'm imagining this isn't possible, so if not can anyone point in the direction of the best way to apply the extension method - there might be up to 50 fields spread across all sorts of classes in my domain model.