ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

Self

Provides Self method for all classes. This is useful inside a With block (when you don't want to declare a variable which references the object you are working with) as it allows you to assign the newly instantiated object. Use this when instantiating objects to which you need a moment's reference.

Source

<Runtime.CompilerServices.Extension()> _
Function Self(Of T)(ByVal x As T) As T
    Return x
End Function

Example

With MyDataSet.Tables("SuperUsers")
  With .NewRow() 
    .Item("FirstName") = "Mario"
    .Item("LastName") = "Lanza"
    .Item("SecurityLevel") = 10
    .Rows.Add(.Self)
  End With
End With

Author: Mario T. Lanza

Submitted on: 28 jan 2009

Language: VB

Type: System.Object

Views: 4774