向 DataColumn 添加属性
我正在创建一个报告组件,它接受 IEnumerable
输入并执行一些转换和聚合,并返回一个具有动态列数的新 IEnumerable
。我为此使用 ADO.NET,因为使用适当的列创建 DataTable
很容易。
转换后的 IEnumerable 被发送到报告可视化组件,该组件使用属性中存储的信息来很好地格式化结果。一旦应用了属性,就没有必要能够删除或更改它们。
我的问题是这样的: 是否可以将 Attribute
与 DataColumn
关联,以便 ADO.NET DataView
发出的 PropertyDescriptor
包括这些属性?
后续问题: 如果 ADO.NET 无法实现此目的,是否可以使用其他库来实现此目的?
编辑:为了清晰起见更新 我希望能够做这样的事情:
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
{
}
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 the 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
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 DataColumn 上的 ExtendedProperties 属性。这允许您将自定义数据添加到数据列。然而,您必须自己编写使用此自定义数据的代码 - 格式化(或您打算使用数据的目的)不是自动的。
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.
回答我自己的问题:不可能将属性注入到 DataColumn 中并让它们出现在 DataView 的 ITypedList 实现发出的 PropertyDescriptor 中
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