Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function ParseData() As String
Dim value as string = GetValue()
End Function
Private Shared Function GetValue() as String
Return "halp"
End Function
End Class
或
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Function ParseData() As String
Dim value as string = GetValue()
End Function
Private Function GetValue() as String
Return "halp"
End Function
End Class
如果必须共享,则使用第一个。如果您可以先初始化对象,或者从同一类中调用它,请使用第二个对象。
正如您所指出的,webmethod必须是共享的(静态的)。在这种情况下,还必须共享从WebMethod调用的方法。
编辑
:
另一种选择是为“getValue”创建单独的类
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function ParseData() As String
Dim util As Utilities = New Utilities
Dim value as string = util.GetValue()
End Function
End Class
Public Class Utilities ''# Utilities is completely arbitrary, you can use whatever you like.
Public Function GetValue() as String
Return "halp"
End Function
End Class