tags:

views:

49

answers:

1

Hi,

I'm writing a class-library in VB.Net and one of the subs that are being called from the application which is using my library has more or less the following syntax:

Public Sub LoadDict(ByVal PhoneticType As String, ByVal strDict As String)

where PhoneticType can be phonSoundex, phonDoubleMetaphone or noPhonetic

I want to give the application-developer a possibility to select the PhoneticType from a list when writing the call of above sub (I think it's called attribute-arguments). This would make it easier for the developer since spelling-errors can be avoided and which will avoid errors when using the library.

I think it's all about attributes but I haven't managed to get it to work despite trying.

Anyone who could post an example how to use attributes and including arguments. If the arguments could be made compulsory, that would be even better.

Thank you.

+6  A: 

If PhoneticType is limited to a small set of defined values, an Enum is probably your best choice.

Enum PhoneticType
  phonSoundex
  phonDoubleMetaphone
  noPhonetic
End Enum

This will help prevent spelling errors you mentioned and additionally IDE's like Visual Studio will provide intellisense taking the developer straight to the allowed value list.

Public Sub LoadDict(ByVal pt As PhoneticType, ByVal strDict As String)

...

LoadDict(PhoneticType.noPhonetic, False)
JaredPar
Thank you. This was exactly what I was looking for. I just tried and it works great. I owe you a beer.
moster67