Attribute Conversion Confusion
There's a difference when defining attribute between C# and Visual Basic.
I was converting the following code snippet, a typical WCF contract definition. (In fact, it was taken from a ChatRoom sample from netfx3.com.)
[ServiceContract(Session = true, CallbackContract = typeof(IChatCallback))]
interface IChat
Logically, the attribute part should be translated into this in VB:
<ServiceContract(Session = true, CallbackContract = GetType(IChatCallback))> Public Interface IChat
Well, it's not. First of all, there is no such thing as assignment operation in parameter area (the above code is constructor call of ServiceContract attribute class. The Intellisense gave away unhelpful cue to do the above conversion. It displays tooltip like:
New([CallbackContract As System.Type], [ConfigurationName As String], ... and so on. Based on the info, I tried giving all of the information it requests by coding it like this:
<ServiceContract(GetType(IchatCallback), , ... and so on. In the end, VS complains about “Too many arguments to 'Public Sub New()'.” Using the Object Explorer, clearly that the definition of the constructor is without parameter. After digging through samples, luckily there's a hint on one of the samples from MSDN. You should use “:=” in place of “=” to do the assignment in VB. So the above C# code can be translated into:
<ServiceContract(Session:=true, CallbackContract:=GetType(IChatCallback))> Public Interface IChat
That line, does the job.