1

stupid question here. I'm trying to create a helper method, something similar to the radio button list in the MVC futures project (as a learning tool).

I'm trying to convert the C# code:

 public static string[] RadioButtonList(this HtmlHelper htmlHelper, string name, IDictionary<string, object> htmlAttributes) {

to a method signature in VB.net, but I'm not sure how to write the first parameter in VB.net, or what you would call this, so I could look it up?

4 Answers 4

2

I believe this will work as long as you remember to mark it as an extension method, you could look up Extension Methods on MSDN.com. They have examples of how to write extension methods in VB.net.

<System.Runtime.CompilerServices.Extension> _
Public Shared Function RadioButtonList(ByVal htmlHelper As HtmlHelper, ByVal name As String, ByVal htmlAttributes As IDictionary(Of String, Object)) As String()
    
End Function
Sign up to request clarification or add additional context in comments.

Comments

2

I'm not either. But this is the signature of an extension method. Here's the MSDN docs on doing this in VB.

Comments

1

They are called Extension methods, and are declared in VB.Net like this:

<System.Runtime.CompilerServices.Extension()> _
Public Sub RadioButtonList(ByVal name As String, ...)
// There's no "this" parameter at all...

Comments

1

Extension methods in VB can only be declared from within a module, not a class, so a complete skeleton definition would look something like this...

Imports System.Web.Mvc

Public Module MyModule

    <System.Runtime.CompilerServices.Extension> _
    Public Function MyHelper (ByVal helper As HtmlHelper, MyParameter as String) As String

    End Function

End Module

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.