Helper class for working with 'extended' enums using StringValueAttribute attributes.
Example #1
0
 /// <summary>
 /// Determina a string exata de uma enum para comparação
 /// </summary>
 /// <param name="tipoEnum"></param>
 /// <returns></returns>
 private static string RetornarStringEnum(Type tipoEnum)
 {
     var enumInstance = new StringEnum(tipoEnum);
     var textoEnum = "";
     foreach (var stringValue in enumInstance.GetStringValues())
     {
         textoEnum += string.Format(@"""{0}"" | ", stringValue);
     }
     return textoEnum;
 }
Example #2
0
 public void TestInstancePropertyEnum()
 {
     StringEnum stringEnum = new StringEnum(typeof(EnumWithoutStrings));
     Assert.IsTrue(stringEnum.EnumType.IsEnum);
 }
Example #3
0
        public void TestInstanceGetStringValues()
        {
            StringEnum stringEnum = new StringEnum(typeof(EnumWithoutStrings));
            Assert.AreEqual(0, stringEnum.GetStringValues().Length);

            stringEnum = new StringEnum(typeof(EnumPartialStrings));
            Assert.AreEqual(1, stringEnum.GetStringValues().Length);
            Assert.AreEqual("Jack be nimble", stringEnum.GetStringValues().GetValue(0).ToString());
        }
Example #4
0
 public void TestInstanceIsStringDefined()
 {
     StringEnum stringEnum = new StringEnum(typeof(EnumWithStrings));
     Assert.IsFalse(stringEnum.IsStringDefined("Something that's not there"));
     Assert.IsFalse(stringEnum.IsStringDefined("first value"));
     Assert.IsTrue(stringEnum.IsStringDefined("First Value"));
 }
Example #5
0
 public void TestInstanceGetStringValue()
 {
     StringEnum stringEnum = new StringEnum(typeof(EnumWithStrings));
     Assert.AreEqual("Fourth Value", stringEnum.GetStringValue("Lazy"));
     //Expect null as this value doesn't exist
     Assert.IsNull(stringEnum.GetStringValue("clearly not there"));
 }