views:

24

answers:

1

Hello,

I have this little piece of code :

    private Dictionary<string, IList<KeyValuePair<int, string>>> EnumsCollection = new Dictionary<string, IList<KeyValuePair<int, string>>>();

    // ...... Dictionary is filled, fine

    // ... outer loop
    foreach (var enumNameAndValue in EnumsCollection[enumName])
    {
         var codeProperty = new CodeMemberField
         {
              Name = enumNameAndValue.Value
         };

         codeClass.Members.Add(codeProperty);
    }
    // ...

Good, I get an enum : public enum eShape { Round, Square, }

but would it be possible to also set a Value moreover the Name? As in :

public enum eShape
{
    Round = 4,
    Square = 5,
}
+1  A: 

You'd use InitExpression:

foreach (var enumNameAndValue in EnumsCollection[enumName])
{
     var codeProperty = new CodeMemberField
     {
          Name = enumNameAndValue.Value,
          InitExpression = new CodePrimitiveExpression(enumNameAndValue.Key); // Uses key for value
     };
Reed Copsey
Thank you! That's all I wanted to know :p I learn something new everyday
ibiza