-3

I am using a Public Enum in a Class Library that is used within different classes within the library. I don't want it exposed to any applications that use the Class Library. I tried changing it to Private, but it says it has to reside within a Class to do that (which I can't do because it is used by many classes). How do I 'hide' it?

EDIT: Sorry about no code. Here's some code from the Class Library (I know it's vb, but I figure c# knowledge will be applicable?)

Public Enum HttpMethod
    [Get]
    Post
    Put
End Enum

Public Class WebClientProcessor
    Public Function HttpAction(netquery As String, method As HttpMethod, Optional json As String = Nothing) As WebClientResponse
    ' Stuff here
    End Function
End Class

Public Class Main
    Public Sub DoStuff
        Dim wcp As New WebClientProcessor
        wcr = wcp.HttpAction(StringOp.UrlCombine(_baseSiteURL, _licenseEndpointsMap(RequestType), LicenseKey), HttpMethod.Get)
    End Sub
End Class
stigzler
  • 793
  • 2
  • 12
  • 29
  • 1
    Can you provide some code so we can have a more clear context ? Thanks – cozmin-calin Jun 16 '21 at 09:12
  • 4
    Use `internal`. – SomeBody Jun 16 '21 at 09:13
  • Can you explain these vague sentences: "*Hide Class Library Enums from applications*" as well as "*a Public Enum in a Class Library that is used within different classes within the library*" and "*don't want it exposed to any applications that use the Class Library*" and "*changing it (what? type or instance?) to Private*", for example with some code, please? –  Jun 16 '21 at 09:20
  • 5
    It's `Friend` in vb.net. `Friend Enum HttpMethod ... End Enum`. – dr.null Jun 16 '21 at 10:20
  • 4
    Don't put your solution in the question. If you don't need an answer tot he question then delete the question, otherwise add an answer with the solution. – jmcilhinney Jun 16 '21 at 10:38

2 Answers2

2

Use the internal modifier.

Internal types or members are accessible only within files in the same assembly.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/internal

lrpe
  • 730
  • 1
  • 5
  • 13
  • 3
    And this is a perfect example of why you don't spam tags. Now there's an answer that was perfectly legitimate based on the tags but is actually irrelevant to the actual question. – jmcilhinney Jun 16 '21 at 10:38
1

I eventually solved it by removing the "Public" just to read:

Enum HttpMethod
    [Get]
    Post
    Put
End Enum
stigzler
  • 793
  • 2
  • 12
  • 29
  • 2
    I thought that enumerations became public by default if it wasn't explicitly stated. Is it getting treated as Internal\Friend instead? – Ryan Roos Jun 16 '21 at 13:59