I'm trying to figure out what the best method is for attaching a single key/value pair attribute to an enumeration where the key is my MerchantId and the value is the corresponding TransactionKey.
What I currently do is put a comma delimited string into a StringValueAttribute
class:
Public Enum Merchants
<StringValue("coke,faj80785hq+faf=-1=-jfa+">
Coke = 0
<StringValue("pepsi,adfji=-901jnas++fdj98ua")>
Pepsi = 1
<StringValue("drpepper,jk878-=+9kdkdja0=a=f--daj")>
DrPepper = 2
End Enum
Public Property Merchant As Merchants
I pull out the key or MerchantId by calling .GetStringValue().Split(","c)(0)
:
Public ReadOnly Property MerchantId() As String
Get
Return Merchant.GetStringValue().Split(","c)(0)
End Get
End Property
I pull out the value or TransactionKey by calling .GetStringValue().Split(","c)(1)
:
Public ReadOnly Property TransactionKey() As String
Get
Return Merchant.GetStringValue().Split(","c)(1)
End Get
End Property
Is this the most efficient way to do this? Instead of StringValueAttribute
, what about creating an attribute using a Dictionary(Of String, String)
since it is a key/value pair list? Or String Array or List? Maybe something in LINQ? Or is it simply already efficient as it can be?