我在我的C#程序中使用了一个CLR的外部库,外部库里有个类是这样的:
public value class SubSetInfo
{
public:
UINT PrimType;
UINT VertexStart;
UINT IndexStart;
UINT PrimCount;
};
由于无法修改这个CLR库的代码,而我的程序里,在一些关键问题上使用了Class和Field的Custom Attribute机制,因此我在C#里面想为这个类和这个类下面的4个Field分别添加一些Attribute。
类我用的是TypeDescriptor:
TypeDescriptor.AddAttributes(typeof(GCRenderFunctional.SubSetInfo), new AutoSerialClassAttribute());但是对于下面的四个Field该怎么增加一些新的Attribute呢?
如果不能增加,那么还有什么好点的方法可以实现这个目的么?
public value class SubSetInfo
{
public:
UINT PrimType;
UINT VertexStart;
UINT IndexStart;
UINT PrimCount;
};
由于无法修改这个CLR库的代码,而我的程序里,在一些关键问题上使用了Class和Field的Custom Attribute机制,因此我在C#里面想为这个类和这个类下面的4个Field分别添加一些Attribute。
类我用的是TypeDescriptor:
TypeDescriptor.AddAttributes(typeof(GCRenderFunctional.SubSetInfo), new AutoSerialClassAttribute());但是对于下面的四个Field该怎么增加一些新的Attribute呢?
如果不能增加,那么还有什么好点的方法可以实现这个目的么?
解决方案 »
- 网上搜不到的答案 C# 如何读取串口数据里 我指定的字节的参数呢?
- 使用GDI+编写操作任意一张图片任意一种功能的代码
- 求救,asp.net怎么生成静态页面?
- 弱弱地问一下,DataRow是否要以保存SqlDataReader读出的东西?
- 当我点击treeView激发它的BeforeSelect或者AfterSelect事件后,只能是点击鼠标左键才算选定了某对象,e才有意义,可是我想右键算呢?
- C#怎么用MD5对文件加密,
- vs2010 普通用户可以下载的版本
- 跪求高手能将下面vb6代码改写成c#的代码,小弟在此谢过了.^_^
- sa登录没有问题了但是不能显示数据是怎么回事啊!
- C#中的#怎么发音啊??
- 浏览器地址显示网站logo
- List<point> 泛型问题!
ref class等同于C#中的class
struct不能继承啊,class还是继承来的好些.
TypeDescriptor.AddAttributes(
typeof(GCRenderFunctional.SubSetInfo),
new AutoSerialClassAttribute (
new string[]
{
"PrimType",
"VertexStart",
"IndexStart",
"PrimCount"
}
)
);
解析的时候也用TypeDescriptor反解 AttributeCollection ac = TypeDescriptor.GetAttributes(type);
AutoSerialClassAttribute asc = null;
foreach (Attribute att in ac)
{
asc = att as AutoSerialClassAttribute;
if (asc != null)
{
return asc;
}
}
return null;
TypeDescriptor还是很强大的啊。
就此结贴吧,需求算是满足了。