1

I want to be able to declare a static list of strings in VB.NET like this:

Public Class AccessTypes   
 Public Shared ViewRights As String = "viewrights"   
 Public Shared EditRights As String = "editrights"
End Class

Then, in a function I want to pass AccessType as a parameter like this:

Public Shared Function CheckAccess(ByVal AccessType As String) As Boolean
'-- check access code
'-- return true/false
End Function

When checking access, I can pass:

CheckAccess(AccessTypes.ViewRights)

but I can also pass:

CheckAccess("randomstring")

Is there a way that I can only pass one of the members of AccessType Class and not just any random string.

I know there is something terribly wrong with the above code. Any advise would be helpful.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Prashant Agarwal
  • 729
  • 7
  • 23
  • @Plutonix this is not a duplication of the question you gave. – Green Fire Sep 18 '17 at 18:02
  • The question referred in duplicate does not talk about restricting value passed to the function as subset of the class. I want to be able to use CheckAccess(AccessTypes.ViewRights) and also CheckAccess(AccessTypes.EditRights) at different places. – Prashant Agarwal Sep 18 '17 at 18:03
  • 1
    Public Shared Function CheckAccess(ByVal xAccess As AccessTypes) As boolean –  Sep 18 '17 at 18:12
  • It absolutely shows how to limit arguments to a certain type. `As String` means any string, `As Test` in the dupe or whatever you name it does exactly that. – Ňɏssa Pøngjǣrdenlarp Sep 18 '17 at 18:14
  • @Plutonix definitely not, I suggest you read the question slowly and see the clear relevant differences. – Green Fire Sep 18 '17 at 18:21

0 Answers0