本文介绍了使用CodeDOM动态生成代码中的自定义PropertyDescriptor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

你好

 

我试图在运行时使用codeDOM生成一些类.

I am trying to generate some classes at runtime using codeDOM.

我想在运行时生成自定义属性描述符,以便可以根据需要将其用于在属性网格中显示属性.

I want to generate a custom property descriptor at runtime so that it can be used to display property in the property grid as i desire.

 

但是当我尝试动态生成自定义属性描述符时,代码会编译,但是在尝试初始化xmlSerializer时会崩溃.

but when i tried to generate the custom property descriptor dynamicaly then the code compiles but while trying to initialize the xmlSerializer it crashes.

下面是它崩溃的行.

XmlSerializer ser =新的XmlSerializer(types [0],types.ToArray());

XmlSerializer ser = new XmlSerializer(types[0], types.ToArray());

这里,types [0]是主要类型,它包含其他一些动态生成的类的属性.

here types[0] is the main type which contains properties of some other dynamically generated classes.

其他动态生成的类和主类位于类型数组中.

The other dynamically generated classes and the main class are present in the types array.

 

我收到以下崩溃消息.

任何人都可以建议如何解决此消息中提到的Add方法的问题.

Can any one suggest how to go around the problem of Add method which is mentioned in this message.

在我看来,这似乎是属性描述符类的问题,该类继承自具有属性类型AttributeCollection的MemberDescriptor.

To me this seems to be the problem with the property descriptor class, which inherits from MemberDescriptor which has a property of type AttributeCollection.

 

以下是消息:

System.InvalidOperationException:反映类型的错误. <类型名称> ---> System.InvalidOperationException:要进行XML序列化,请继承自ICollection的类型 必须在其继承层次结构的所有级别上都具有Add(System.Attribute)的实现. System.ComponentModel.AttributeCollection没有实现Add(System.Attribute).

System.InvalidOperationException: There was an error reflecting type. <Type Name> ---> System.InvalidOperationException: To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.Attribute) at all levels of their inheritance hierarchy. System.ComponentModel.AttributeCollection does not implement Add(System.Attribute).

推荐答案


这篇关于使用CodeDOM动态生成代码中的自定义PropertyDescriptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:55