Tuesday, 19 October 2010

Anonymous Types

While creating a server/client app, I need to send a blob of information without the hassle of shared classes when using serialise / deserialise. After messing with my own serialiser (which worked and was ugly) I came across Anonymous Types. These little beauties let you create a type on the fly without prior declarations and are great for times when you need to store data for on a single occasion. Behold ....

MyData = New With {
      .ID = 999, 
      .Name = "SGs solarium",
      .Value = 999.99
      .Info = "Test anonymous types"
}

Later on you can then use the above like any other type.

As you can see by the lack of line continuation this is a 2010 only sample (maybe 2008, haven't tested that)

No comments:

Post a Comment