Add attributes to DataColumn
I am creating a reporting component that takes an IEnumerable
input and performs some transformations and aggregations and returns a new IEnumerable
with a dynamic number of columns. I am using ADO.NET for this because it is easy to create a DataTable
with the appropriate columns.
The transformed IEnumerable
is sent to a reporting visualization component that uses information stored in Attributes to format t开发者_如何学编程he results nicely. It's not necessary to be able to remove or change the attributes once they have been applied.
My question is this:
Is it possible to associate an Attribute
with a DataColumn
so that the PropertyDescriptor
emitted by the ADO.NET DataView
includes these Attributes?
Follow-up question: If this is not possible with ADO.NET are there other libraries that I can use to accomplish this?
Edit: Update for clarity I would like to be able to do something like this:
DataTable dt = new DataTable();
DataColumn example = dt.Columns.Add("Test",typeof(double));
//This is the functionality I am looking for ideally
example.AddAttribute(new CustomAttribute("Hello"));
public class CustomAttribute : Attribute
{
}
See the ExtendedProperties property on DataColumns. This allows you to add custom data to a datacolumn. You would have to write the code that uses this custom data yourself, however - the formatting (or what ever you intend the data to be used for) isn't automatic.
To answer my own question: It's not possible to inject attributes into a DataColumn and have them appear in the PropertyDescriptor that DataView's implementation of ITypedList emits
精彩评论