I've been trying figure out how to add a handler to a method using Codedom, but am not getting very far.
The method I want to reproduce via Codedom is:
Private Sub Startup() Handles btnStart.Click
''# Do work
End Sub
The method is easy enough to create with:
Dim StartupMethod As New CodeMemberMethod
StartupMethod.Name = "Startup"
StartupMethod.Attributes = MemberAttributes.Private
But I can't figure out how to add the Handles btnStart.Click
. I've looked at CodeAttachEventStatement
, but this I don't believe it can do a Handles
on a method.
Does anyone know how to achieve this?
EDIT: The solution below works for VB, but does not work for C# because the handler is looking to handle an event rather than a method.