|
Imports System.Windows.Forms
Namespace LambdaExamples
Public Class InsaneLambdaButtonFactoryRewritten
Implements IButtonFactory
Private outerCounter As Integer = 1
Public Function GenerateButtons() As System.Collections.Generic.IEnumerable(Of System.Windows.Forms.Button) Implements IButtonFactory.GenerateButtons
Dim iLambda As New InnerLambda
iLambda.Field_Me = Me
Dim list As New List(Of Button)
Dim iILambda As InnerLambda.InnerInnerLambda
iLambda.Local_counter = 1
For i As Integer = 1 To 10
iILambda = New InnerLambda.InnerInnerLambda(iILambda)
iILambda.NonLocal_Inner_InnerLambda = iLambda
iILambda.Local_btn = New Button
iILambda.Local_btn.Text = outerCounter.ToString + " - " + iLambda.Local_counter.ToString
AddHandler iILambda.Local_btn.Click, AddressOf iILambda.EventHandler
list.Add(iILambda.Local_btn)
Next
Return list
End Function
Public Class InnerLambda
Public Local_counter As Integer
Public Field_Me As InsaneLambdaButtonFactoryRewritten
Public Sub New()
End Sub
Public Sub New(ByVal innerLambda As InnerLambda)
If Not innerLambda Is Nothing Then
Field_Me = innerLambda.Field_Me
Local_counter = innerLambda.Local_counter
End If
End Sub
Public Class InnerInnerLambda
Public Local_btn As Windows.Forms.Button
Public NonLocal_Inner_InnerLambda As InnerLambda
Public Sub New()
End Sub
Public Sub New(ByVal innerInnerLambda As InnerInnerLambda)
If Not innerInnerLambda Is Nothing Then
Local_btn = innerInnerLambda.Local_btn
End If
End Sub
Public Sub EventHandler(ByVal sender As Object, ByVal e As EventArgs)
NonLocal_Inner_InnerLambda.Local_counter = NonLocal_Inner_InnerLambda.Local_counter + 1
If NonLocal_Inner_InnerLambda.Local_counter Mod 10 = 0 Then
NonLocal_Inner_InnerLambda.Field_Me.outerCounter = NonLocal_Inner_InnerLambda.Field_Me.outerCounter + 1
End If
Local_btn.Text = NonLocal_Inner_InnerLambda.Field_Me.outerCounter.ToString + " - " + NonLocal_Inner_InnerLambda.Local_counter.ToString
End Sub
End Class
End Class
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Sander Rossel is a Microsoft certified professional developer with experience and expertise in .NET and .NET Core (C#, ASP.NET, and Entity Framework), SQL Server, Azure, Azure DevOps, JavaScript, MongoDB, and other technologies.
He is the owner of
JUUN Software, a company specializing in custom software. JUUN Software uses modern, but proven technologies, such as .NET Core, Azure and Azure DevOps.
You can't miss
his books on Amazon and
his free e-books on Syncfusion!
He wrote a JavaScript LINQ library,
arrgh.js (works in IE8+, Edge, Firefox, Chrome, and probably everything else).
Check out his
prize-winning articles on CodeProject as well!