I would like to know which is the proper practice to follow when need to expose a WinAPI enumeration.
( I think this question affects both C# and VB.Net because just its a member visibility question )
I have a NativeMethods
Class as indicates MSDN to follow best practices when P/Invoking, well, inside my NativeMethods
I have declared the SetSystemCursor
function from Windows API, and also the required Enum for id
parameter of SetSystemCursor
function.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648395%28v=vs.85%29.aspx
Then, I did a little wrapper:
Public Shared Function SetSystemCursor(ByVal filePath As String,
ByVal cursorType As NativeMethods.SystemCursorId) As Boolean
Return NativeMethods.SetSystemCursor(NativeMethods.LoadCursorFromFile(filePath), cursorType)
End Function
Note the cursorType
parameter, the problem is that SystemCursorId
Enum is not public because as I said is part of the platform invoking definitions inside the NativeMethods
class, so, to be able use the wrapper I could do two things, first make public the SystemCursorId
Enum ...this means move the Enum outside the private NativeMethods
Class like this:
Public Class MyClass
Private Class NativeMethods
' ...
End Class
Public Enum SystemCursorId
Arrow = 32512
Crosshair = 32515
End Enum
End Class
Or secondly, re-declare the same Enum outside the NativeMethods
class to expose it, something like this:
Public Class MyClass
Private Class NativeMethods
Friend Enum SystemCursorId
Arrow = 32512
Crosshair = 32515
End Enum
End Class
Public Enum SystemCursorId
Arrow = NativeMethods.SystemCursorId.Arrow
Crosshair = NativeMethods.SystemCursorId.Crosshair
End Enum
End Class
So, in this circunstances, which is the recommended programming practice to follow?.