这是我在这个问题中引用的课程:
Public Class Enums
Public Enum Subscription As Byte
Vendor = 1
FreeTrial = 2
Standard = 3
Enterprise = 4
End Enum
End Class
在 VB.NET 类中,我具有以下属性:
Private _optionSelection1 As String 'added by StackOverflow EDIT
Public Property OptionSelection() As String
Get
Return If(IsNothing(_optionSelection1), String.Empty, _optionSelection1)
End Get
Set(ByVal value As String)
_optionSelection1 = value
End Set
End Property
该属性从 Request.Form 变量中设置如下:'由 StackOverflow 编辑添加
Me.OptionSelection = HttpContext.Current.Request.Form("option_selection1") 'added by StackOverflow EDIT
我稍后在函数中使用此值:
Dim choiceMade As Enums.Subscription = SubscriptionOptionSelected(Me.OptionSelection)
我认为如果它的参数可以比字符串“更强”,函数可能会更强大:
Private Function SubscriptionOptionSelected(ByVal value As String) As Enums.Subscription
Select Case value
Case "S10"
Return Enums.Subscription.Standard
Case "ENT"
Return Enums.Subscription.Enterprise
End Select
End Function
我尝试编写如下函数,但编译器立即抱怨:
Private Function SubscriptionOptionSelected(ByVal value As OptionSelection) As Enums.Subscription
有没有办法使用 Property 作为传递给这个小函数的类型?