VB equiv. of typeof() operator, as it pertains to XmlInclude()annotation

B

Brains

Hopefully this is something trivial that I'm overlooking, but I've
been scratching my head a while trying to find the solution to no
avail.

I can write a web service that returns a complex object in C# just
fine, annotating the web service class with a line such as:
[System.Xml.Serialization.XmlInclude(typeof(SomeComplexObjectClass))]

Unfortunately, I haven't quite figured out how to accomplish the same
thing in VB.NET. An annotation such as:
<System.Xml.Serialization.XmlInclude(Type.GetType
("SomeComplexObjectClass"))>
irritates the compiler with a message stating "Constant expression is
required."

Does anyone have insight into this one?

Thanks!

--Brian
 
T

Tom Shelton

Hopefully this is something trivial that I'm overlooking, but I've
been scratching my head a while trying to find the solution to no
avail.

I can write a web service that returns a complex object in C# just
fine, annotating the web service class with a line such as:
[System.Xml.Serialization.XmlInclude(typeof(SomeComplexObjectClass))]

Unfortunately, I haven't quite figured out how to accomplish the same
thing in VB.NET. An annotation such as:
<System.Xml.Serialization.XmlInclude(Type.GetType
("SomeComplexObjectClass"))>
irritates the compiler with a message stating "Constant expression is
required."

Does anyone have insight into this one?

I think you need VB's GetType operator:

<System.Xml.Serialization.XmlInclude (GetType (SomeComplexObject) ) >

HTH
 
B

Brains

That is exactly what I'd already tried, as noted in my original post.
The compiler complains about it not being a constant expression.

Brian
 
T

Tom Shelton

That is exactly what I'd already tried, as noted in my original post.
The compiler complains about it not being a constant expression.

Brian

Your original post used Type.GetType, which is a static method call on the
Type class, not the VB.NET GetType operator. The are completely different.
For example the following compiles just fine:

Public Class TestingAttribute
Inherits Attribute

Public Sub New(ByVal t As Type)

End Sub

End Class

<Testing(GetType(Integer))> _
Public Class Test

End Class

HTH
 
B

Brains

*slaps forehead* Subtle, but oh so important! Works like a champ
now.

Thank you very much Tom and David!

Brian
 
Top