Wyliczyć z typem powrotu innym niż ciąg?

Ponieważ wyliczenie używa liczb całkowitych, jakiej innej struktury mogę użyć, aby uzyskać dostęp do wartości powiązanej z nazwą:

[Wiem, że to źle, szukam alternatywy]

private enum Project
    {
        Cleanup = new Guid("2ED3164-BB48-499B-86C4-A2B1114BF1"),
        Maintenance = new Guid("39D31D4-28EC-4832-827B-A11129EB2"),
        Upgrade = new Guid("892F865-E38D-46D7-809A-49510111C1"),
        Sales = new Guid("A5690E7-1111-4AFB-B44D-1DF3AD66D435"),
        Replacement = new Guid("11E5CBA2-EDDE-4ECA-BDFD-63BDBA725C8C"),
        Modem = new Guid("6F686C73-504B-111-9A0B-850C26FDB25F"),
        Audit = new Guid("30558C7-66D9-4189-9BD9-2B87D11190"),
        Queries = new Guid("9985242-516A-4151-B7DD-851112F562")
    }

EDYTUJ 2014-07-20

To nowsza odpowiedź na to pytanie. Używając klasy Attribute z metodą pomocniczą, zdefiniuj dodatkowe atrybuty potrzebne w wyliczeniu.

 public enum MultiValueEnum
    {
        [FooAttribute("alpha", 20d, true)]
        First,
        [FooAttribute("beta", 40.91d, false)]
        Second,
        [FooAttribute("gamma", 1.2d, false)]
        Third,
    }     

  public class FooAttribute : Attribute
            {
                internal FooAttribute(string name, double percentage, bool isGood)
                {
                    this.Name = name;
                    this.Percentage = (decimal)percentage;
                    this.IsGood = isGood;
                }
                public string Name { get; private set; }
                public decimal Percentage { get; private set; }
                public bool IsGood { get; private set; }
            }



  public static TAttribute GetAttribute<TAttribute>(this Enum value)
        where TAttribute : Attribute
        {
            var type = value.GetType();
            var name = Enum.GetName(type, value);
            return type.GetField(name)
                .GetCustomAttributes(false)
                .OfType<TAttribute>()
                .SingleOrDefault();
        }

Co czyni to tak łatwym:

        MultiValueEnum enumVar = MultiValueEnum.First;
        var enumStringValue = enumVar.GetAttribute<FooAttribute>().Name;
        var enumValueDecimal = enumVar.GetAttribute<FooAttribute>().Percentage;
        var enumBool = enumVar.GetAttribute<FooAttribute>().IsGood;

questionAnswers(7)

yourAnswerToTheQuestion