Attributes with property values in Visual Basic

This got me once again. It’s really hard to remember!

When you do declarative programming in Visual Basic and you use attributes that have properties, you need to set the values on those properties. VB does this in a funny way.

Here is a C# attribute for BP (Basic Profile) Conformance in a Web Service:

[WebServicesBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

Setting the value of the ConformsTo property is a normal looking equals (=) operator.

But with VB, look at how we set the property

<WebServicesBinding(ConformsTo: = WsiProfiles.BasicProfile1_1)>

We put a colon in front of the equals sign.

This is not new to VB2005, but attributes are something I so rarely use (but will be using more and more as I do more WCF programming) that I forget from one year to the next.

I have never been able to find an explanation of why this is and only know it because I get a compiler error when I forget it ("named argument expected") and I have to see another example of it’s use somewhere before I realize it. Intellisense doesn’t give me a helping hand with it (as far as I have seen in vs2003 or vs2005). So, perhaps by writing this blog post, I can commit this to memory finally!

 

Don’t Forget: www.acehaid.org

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.