Question Overloading Enums

tommykent1210

Member
Joined
Nov 2, 2011
Messages
10
Programming Experience
1-3
Hi there, I am making a library for vb.NET that makes it easy for me to use hashing methods in my other projects, without having to write the same code over and over again in different projects.
I have a function named "ReturnHash". This has 2 versions like so:
Public Enum Method
MD5 = 0
SHA1 = 1
SHA256 = 2
SHA512 = 3
RIPEMD_160 = 4
End Enum

Public Enum NonSaltMethod
CRC_32 = 0
End Enum

'then

Public Overloads Function ReturnHash(ByVal Message As String, ByVal Method As Method, Optional ByVal SaltingType As SaltingType = SaltingType.None, Optional ByVal Salt As String = "")
'Do some stuff
End Function

Public Overloads Function ReturnHash(ByVal Message As String, ByVal Method As NonSaltMethod)
'Do some other stuff
End Function

There needs to be 2 versions, because some hashing methods do not need to support salting. So, I want to overload it. If MD5/SHA-X/RIPEMD are selected form intellisense, then the first function is called, if not the second is.
Now, this works (kind of), because when I call the method ReturnHash() I can put the value I want for the enum in and it switches to the correct function. BUT, the enum values DO NOT appear in the intellisense window :S Until I type "MyLibrary.NonSaltingMethod." the optons do not appear. Is there any way to make all possible options appear, then switch to the correct function after the method is slected? I tried putting them all in one function, but if they are in the same, the "Optional" salt parameters appear even if CRC32 is selected :S

Thanks In Advance
Tom
 
Tom

If you mean the intellisense doesnt work when you call the ReturnHash from other functions then could you try importing MyLibrary from the class you are calling it from. Or, how about declaring the enums outside of the hashing methods class...? Just a few thoughts.

Nic
 
Enum values appear in the Common tab of intellisense dialog. Fast switch Common/All tabs with keyboard shortcut Alt-comma/period.
From what I can see intellisense does not handle two enum overloads very well with the values listing in Common tab.
I would make those one method, adding crc32 to the enum values and leaving the salting as optional. Using salt only when necessary.
I would not use the language word 'Method' as enum identifier, but rather 'HashMethod' for example.
 
Back
Top