Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VB.NET how do you specify Inherits/implements on a generic class with multi-constraints

When I write the following statement in VB.Net (C# is my normal language), I get an "end of statement expected" referring to the "Implements" statement.

<Serializable()> _
<XmlSchemaProvider("EtgSchema")> _
Public Class SerializeableEntity(Of T As {Class, ISerializable, New}) _
Implements IXmlSerializable, ISerializable
...
End Class

The C# version that I'm trying to emulate is:

[Serializable]
[XmlSchemaProvider("MySchema")]
public class SerializableEntity<T> : IXmlSerializable, ISerializable where T : class, new()
{
....
}

Sometimes I feel like I have 5 thumbs with VB.NET :)

like image 590
Romel Evans Avatar asked Dec 15 '25 09:12

Romel Evans


1 Answers

In VB, Implements (and Inherits) is a separate clause within the body of the class (on the same level as class members), so you simply need to drop that _ line continuation:

<Serializable()> _
<XmlSchemaProvider("EtgSchema")> _
Public Class SerializeableEntity(Of T As {Class, ISerializable, New})
    Implements IXmlSerializable, ISerializable
    ...
End Class
like image 187
Pavel Minaev Avatar answered Dec 17 '25 02:12

Pavel Minaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!