开发者

How to get type of class without initiating object?

开发者 https://www.devze.com 2023-02-06 06:19 出处:网络
The consturctor of System.Xml.Serialization.XmlSerial need the type of the class I want to serialize.

The consturctor of System.Xml.Serialization.XmlSerial need the type of the class I want to serialize.

instance = New AnyClass()
Dim xmlszer As New XmlSerializer(instance.G开发者_运维百科etType)

No problem. But how can I get the type of AnyClass without initiating?


Try this:

Dim xmlszer As New XmlSerializer(GetType(AnyClass))

GetType Operator:

Returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events.


Try this instead ;)

Dim xmlszer As New XmlSerializer(GetType(MyClass))
0

精彩评论

暂无评论...
验证码 换一张
取 消