andrew4582

GetEnumFlags

Nov 6th, 2010
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1.     public static string GetEnumFlags(Type enumType)
  2.     {
  3.         //Type enumType = typeof(System.Diagnostics.TraceOptions);
  4.        
  5.         System.Text.StringBuilder builder = new System.Text.StringBuilder();
  6.        
  7.         int maxValue = 0;
  8.         Array values = Enum.GetValues(enumType);
  9.         for(int i=0;i<values.Length;i++){
  10.             int v = Convert.ToInt32(values.GetValue(i));
  11.            
  12.             if(v> maxValue)
  13.                 maxValue = v;
  14.         }
  15.        
  16.         maxValue *= 2;
  17.        
  18.         // Display all possible combinations of values.
  19.         // Also display an invalid value.
  20.         for( int val = 0; val <= maxValue; val++ )
  21.             builder.AppendFormat( "{0,3} - {1}\r\n",
  22.                 val, (Enum.ToObject(enumType,val)).ToString( ) );
  23.        
  24.        
  25.         return builder.ToString();
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment