title: How do I create a GetEnumValues extension method in Silverlight that works the same way as in .NET?
body: <p>Below is a piece of code I find useful in that I can use it to nip round enums quickly.  CurrentEnum stores a reference to the enum that was used to provide the strings, in this case "Bald" and it can change.</p>
  
  <p>What I am trying to do is replicate the same functionality in Silverlight which does not have a GetEnumValues function.  The preferable solution would be an extension method that can be used in the same way as in my example below.</p>
  
  <pre><code>class Program
  {
      enum Cats { Fluffy, Furry, Bald };
      enum Dogs { Big, Fat, Ugly };
  
      static Type CurrentEnum = typeof(Cats);
  
      static void Main(string[] args)
      {
          Int32 i = (Int32)Enum.Parse(CurrentEnum, "Bald", true);
          i = i == CurrentEnum.GetEnumValues().Length - 1 ? 0 : i + 1;
          String nextValue = CurrentEnum.GetEnumValues().GetValue(i).ToString();
  
          Console.WriteLine(nextValue);
          Console.ReadKey();
      }
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>Here is what I have decided on for now:</p>
  
  <pre><code>public static class Extensions
  {
      public static Array GetEnumValues(this Type enumType)
      {
          if (enumType == null) throw new ArgumentException("Type 'enumType' cannot be null");
          if (!enumType.IsEnum) throw new ArgumentException("Type '" + enumType.Name + "' is not an enum");
  
          Int32 i = 0;
          Boolean bDefined = true;
          List&lt;String&gt; list = new List&lt;String&gt;();
  
          do
          {
              if (Enum.IsDefined(enumType, i))
              {                    
                  list.Add(Enum.GetName(enumType, i));
                  ++i;
              }
              else
              {
                  bDefined = false;
              }
          }
          while (bDefined);
  
          return list.ToArray();
      }
  }
  </code></pre>