System.Security.Util.XMLUtil.BitFieldEnumToString C# (CSharp) Method

BitFieldEnumToString() public static method

public static BitFieldEnumToString ( Type type, Object value ) : String
type System.Type
value Object
return String
        public static String BitFieldEnumToString( Type type, Object value )
        {
            int iValue = (int)value;

            if (iValue == 0)
                return Enum.GetName( type, 0 );

            StringBuilder result = new StringBuilder();
            bool first = true;
            int flag = 0x1;

            for (int i = 1; i < 32; ++i)
            {
                if ((flag & iValue) != 0)
                {
                    String sFlag = Enum.GetName( type, flag );

                    if (sFlag == null)
                        continue;

                    if (!first)
                    {
                        result.Append( ", " );
                    }

                    result.Append( sFlag );
                    first = false;
                }

                flag = flag << 1;
            }
            
            return result.ToString();
        } 
    }