I have a class that helps me read data from an MS SQL database into a list of objects. For the most part it's pretty straightforward; I can assume the property name of the class matches the column name of the table and just assign it accordingly, but sometimes I need to be able to transform data.
I have created a custom attribute to put on my class properties:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class TransformDataAttribute : Attribute
{
public Func<object, string, object> TransformThisData { get; set; }
}
Now, let's say I want to create the Func on the fly, like this:
[TransformData(TransformThisData = new Func<object, string, object>((v, p) => "My name is " + v.ToString()))]
public string Name { get; set; }
The error that I am seeing is 'TransformThisData' is not a valid named attribute argument because it is not a valid attribute parameter type.
What is the best way to accomplish Func as a property attribute?