GetFlagList() private static method

Splits a bitwise-OR'd set of enums into a list.
from PseudoCode.EnumHelper
private static GetFlagList ( Type enumType, object value ) : System.Enum[]
enumType System.Type the enum type
value object the combined value
return System.Enum[]
Exemplo n.º 1
0
        public virtual void Write(Enum value)
        {
            string enumName = null;

            Type type = value.GetType();

            if (type.IsDefined(typeof(FlagsAttribute), true) && !Enum.IsDefined(type, value))
            {
                Enum[]   flags     = JsonWriter.GetFlagList(type, value);
                string[] flagNames = new string[flags.Length];
                for (int i = 0; i < flags.Length; i++)
                {
                    flagNames[i] = JsonNameAttribute.GetJsonName(flags[i]);
                    if (String.IsNullOrEmpty(flagNames[i]))
                    {
                        flagNames[i] = flags[i].ToString("f");
                    }
                }
                enumName = String.Join(", ", flagNames);
            }
            else
            {
                enumName = JsonNameAttribute.GetJsonName(value);
                if (String.IsNullOrEmpty(enumName))
                {
                    enumName = value.ToString("f");
                }
            }

            this.Write(enumName);
        }
Exemplo n.º 2
0
        public virtual void Write(Enum value)
        {
            Type   type = value.GetType();
            string value2;

            if (type.IsDefined(typeof(FlagsAttribute), true) && !Enum.IsDefined(type, value))
            {
                Enum[]   flagList = JsonWriter.GetFlagList(type, value);
                string[] array    = new string[flagList.Length];
                for (int i = 0; i < flagList.Length; i++)
                {
                    array[i] = JsonNameAttribute.GetJsonName(flagList[i]);
                    if (string.IsNullOrEmpty(array[i]))
                    {
                        array[i] = flagList[i].ToString("f");
                    }
                }
                value2 = string.Join(", ", array);
            }
            else
            {
                value2 = JsonNameAttribute.GetJsonName(value);
                if (string.IsNullOrEmpty(value2))
                {
                    value2 = value.ToString("f");
                }
            }
            this.Write(value2);
        }