开发者

call method after dot, not in parenthsis

开发者 https://www.devze.com 2023-03-16 05:25 出处:网络
Assume I have a function: Protected Sub UploadFile(file As String) ....... End Sub Then I can do the follwing开发者_运维问答

Assume I have a function:

Protected Sub UploadFile(file As String)
    .......
End Sub

Then I can do the follwing开发者_运维问答

UploadFile(file)

But I would like to do this:

file.UploadFile()

Looks like Im missing logic in here, but still - is it possible to make dot-like notation?


I think you want an Extension method.

Module StringExtensions
  <Extension()> 
  Public Sub Upload(ByVal fileName As String)
      ' ... Upload the file, now.
  End Sub
End Module


I'm assuming that upload file is a method you're trying to invoke on the same class you defined it on. If that's the case, all you have to do is

 this.UploadFile();

and adjust the UploadFile() method to read the file from a member variable instead of a parameter.

Hope that gives you enough info to get started.

0

精彩评论

暂无评论...
验证码 换一张
取 消