In VB.NET it is actually possible to return an Anonymous type from a function and use it somewhere else. In VB.NET you need to use late binding so you can’t change the “Option strict” compiler option to true as I have always done in the past. This option, that defaults to “Off”, is the main reason that C# developers scoff at VB, but this feature is now available, controversially in C#.
In this example I created an anonymous type that has three properties.
Public Function GetTwiterCredentials() As Object If Not My.Settings.TwitterEmail.Length > 3 Then GetSettings() End If If Not My.Settings.TwitterPassword.Length > 3 Then GetSettings() End If If Not My.Settings.TwitterUsername.Length > 3 Then GetSettings() End If Return New With { _ .Email = My.Settings.TwitterEmail, _ .Password = My.Settings.TwitterPassword, _ .Username = My.Settings.TwitterUsername _ } End Function
The use of this is very simple, although I would like an option other than to return “Object” so Visual Studio knows that it is an anonymous type.
Dim TwiterCredentials = View.GetTwiterCredentials Dim result As String = "" result = Twitter.TwitterAPI.UpdateStatus( _ status, _ TwiterCredentials.Email, _ TwiterCredentials.Password _ )
There is no intellisense with this, so you have to know what the options are. Hopefully in future versions this will be rectified.
Technorati Tags: .NET
What to read next
My first Extension method
Explains how to create and use extension methods in VB.NET, with an example for enhancing the XboxInfo class to display and track Xbox Live …
Where am I?
Describes a .NET application that tracks users’ locations via IP, updates Active Directory, and uses LINQ for database queries, aiding …
My.Unity.Resolve(Of Ninja)
Shows how to create a shared UnityContainer singleton in VB.NET using the “My” namespace, enabling dependency injection across WPF and …
Detecting agile theatre with real delivery signals
Why Most Companies Operating Models Fail in Dynamic Markets
A concise comparison of Predictive and Adaptive Operating Models, explaining why traditional structures fail in dynamic markets and how …
Don’t Manage Dependencies, Remove Them
Explains why dependencies are a sign of poor system design and outlines steps to eliminate them by aligning teams, clarifying ownership, and …
The Estimation Trap: How Tracking Accuracy Undermines Trust, Flow, and Value in Software Delivery
Tracking estimation accuracy in software delivery leads to mistrust, fear, and distorted behaviours. Focus on customer value, flow, and …
Flow of Value vs Flow of Work – Misnomer or Useful Shorthand?
Compares “flow of value” and “flow of work” in Kanban, explaining why only validated outcomes count as value and stressing the need for …
Why Outsourcing DevOps Fails, and How Real Engineering Excellence Starts With Your Team
Avoid DevOps vendor lock-in, discover how true engineering excellence starts with partnership, not outsourcing. Ready to transform your …