示例#1
0
        public static System.Enum EnumPopup(Rect rect, string label, System.Enum enumerator, string[] minus)
        {
            System.Array  optionsEnums        = System.Enum.GetValues(enumerator.GetType());
            string[]      options             = System.Enum.GetNames(enumerator.GetType());
            string        selectedName        = System.Enum.GetName(enumerator.GetType(), enumerator);
            List <string> OriginalListOptions = ArrayUtility.ArrayToList(options);
            List <string> FilteredListOptions = ArrayUtility.ArrayToList(options);

            for (int i = 0; i < minus.Length; i++)
            {
                if (FilteredListOptions.Contains(minus[i]))
                {
                    FilteredListOptions.Remove(minus[i]);
                }
            }
            int selectedIndex = FilteredListOptions.IndexOf(selectedName);

            selectedIndex = EditorGUI.Popup(rect, label, selectedIndex, FilteredListOptions.ToArray());
            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            selectedName = FilteredListOptions[selectedIndex];
            int nonfilteredSelectedIndex = OriginalListOptions.IndexOf(selectedName);

            return((System.Enum)(optionsEnums.GetValue(nonfilteredSelectedIndex)));
        }
 private void FilterLists(System.Enum _incEnum)
 {
     if (_incEnum.GetType() == typeof(E_ActionType))
     {
     }
     if (_incEnum.GetType() == typeof(E_TransitionDecisionType))
     {
     }
 }
示例#3
0
        /// <summary>
        /// Gets the string value of a description attribute of an enum
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetEnumDescription(System.Enum enumValue)
        {
            var enumMember        = enumValue.GetType().GetMember(enumValue.ToString()).FirstOrDefault();
            var descriptionAttrbs = enumMember.GetCustomAttributes(typeof(DescriptionAttribute), true);

            return(((DescriptionAttribute)descriptionAttrbs[0]).Description);
        }
示例#4
0
 public static string GetDisplayName(System.Enum enumValue)
 {
     return(enumValue.GetType().GetMember(enumValue.ToString())
            .First()
            .GetCustomAttribute <DisplayAttribute>()
            .Name);
 }
示例#5
0
        public static string ToFriendlyString(this System.Enum me)
        {
            var enumType   = me.GetType();
            var enumString = me.ToString();

            return(FriendlyStrings.GetOrAdd($"{enumType.FullName}.{enumString}", key => GetDescription(me)));
        }
示例#6
0
    public static T GetAttribute <T>(this System.Enum value)
    {
        FieldInfo fi         = value.GetType().GetField(value.ToString());
        var       attributes = fi.GetCustomAttributes(typeof(T), false);

        return(attributes.Length > 0 ? (T)attributes[0] : default(T));
    }
示例#7
0
        /// <summary>
        /// Get description of current enum from System.ComponentModel.DescriptionAttribute or ToString() method
        /// </summary>
        /// <param name="value">bind to enum</param>
        /// <returns>string</returns>
        public static string Description(this System.Enum value)
        {
            if (value == null)
            {
                return(string.Empty);
            }
            var enumType     = value.GetType();
            var defaultValue = System.Enum.GetName(enumType, value);

            if (defaultValue == null)
            {
                return(string.Empty);
            }
            var field = enumType.GetField(defaultValue);

            if (field == null)
            {
                return(defaultValue);
            }
            var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes.Length == 0
                                           ? defaultValue
                                           : ((DescriptionAttribute)attributes[0]).Description);
        }
        public static void SetEnumValue(this SerializedProperty prop, System.Enum value)
        {
            if (prop == null)
            {
                throw new System.ArgumentNullException("prop");
            }
            if (prop.propertyType != SerializedPropertyType.Enum)
            {
                throw new System.ArgumentException("SerializedProperty is not an enum type.", "prop");
            }

            if (value == null)
            {
                prop.enumValueIndex = 0;
                return;
            }

            int i = prop.enumNames.IndexOf(System.Enum.GetName(value.GetType(), value));

            if (i < 0)
            {
                i = 0;
            }
            prop.enumValueIndex = i;
        }
示例#9
0
        private static string _GetActionSet(System.Enum i)
        {
            var actionSet = ((System.ComponentModel.DescriptionAttribute)i.GetType().GetMember(i.ToString())[0].GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false)[0]).Description;

            //return string.Format("/actions/{0}/in/{1}",actionSet,i.ToString().ToLower());
            return(actionSet);
        }
示例#10
0
        public static string ToDescription(this System.Enum value)
        {
            FieldInfo fi         = value.GetType().GetField(value.ToString());
            var       attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes.Length > 0 ? attributes[0].Description : value.ToString());
        }
示例#11
0
        // http://stackoverflow.com/questions/4108828/generic-extension-method-to-see-if-an-enum-contains-a-flag
        public static bool HasFlag(this System.Enum variable, System.Enum value)
        {
            if (variable == null)
            {
                // don't throw an argument null exception; a null value just isn't present.
                return(false);
            }

            if (value == null)
            {
                throw new System.ArgumentNullException("value");
            }

            var variableType = variable.GetType();

            if (!System.Enum.IsDefined(variableType, value))
            {
                var message = string.Format("Enumeration type mismatch.  The flag is of type '{0}', was expecting '{1}'.",
                                            value.GetType(), variableType);
                throw new System.ArgumentException(message, "value");
            }

            ulong num = System.Convert.ToUInt64(value);

            return((System.Convert.ToUInt64(variable) & num) == num);
        }
示例#12
0
        public string ObterDescricaoDoEnum(System.Enum enumValor)
        {
            var fi         = enumValor.GetType().GetField(enumValor.ToString());
            var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes.Length > 0 ? attributes[0].Description : enumValor.ToString());
        }
示例#13
0
        public static string GetDescription(this System.Enum enumValue)
        {
            var fieldInfo  = enumValue.GetType().GetField(enumValue.ToString());
            var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes.Length > 0 ? attributes[0].Description : enumValue.ToString());
        }
示例#14
0
 public static string GetDescription(System.Enum value)
 {
     System.Reflection.FieldInfo fi = value.GetType().GetField(value.ToString());
     System.ComponentModel.DescriptionAttribute[] attributes =
         (System.ComponentModel.DescriptionAttribute[])fi.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
     return((attributes.Length > 0) ? attributes[0].Description : value.ToString());
 }
示例#15
0
 /// <summary>
 /// 获取Enum的描述
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string GetDescription(this System.Enum value)
 {
     return(value.GetType()
            .GetMember(value.ToString())
            .FirstOrDefault()?
            .GetCustomAttribute <DescriptionAttribute>()?
            .Description);
 }
示例#16
0
 /// <summary>
 /// 获取枚举描述,使用System.ComponentModel.Description特性设置描述
 /// </summary>
 /// <param name="instance">枚举实例</param>
 public static string Description(this System.Enum instance)
 {
     if (instance == null)
     {
         return(string.Empty);
     }
     return(Enum.GetDescription(instance.GetType(), instance));
 }
示例#17
0
 /// <summary>
 /// 获取枚举值
 /// </summary>
 /// <param name="instance">枚举实例</param>
 public static int Value(this System.Enum instance)
 {
     if (instance == null)
     {
         return(0);
     }
     return(Enum.GetValue(instance.GetType(), instance));
 }
示例#18
0
 /// <summary>
 /// Get the Description from the DescriptionAttribute.
 /// </summary>
 /// <param name="enumValue"></param>
 /// <returns></returns>
 public static string GetDescription(this System.Enum enumValue)
 {
     return(enumValue.GetType()
            .GetMember(enumValue.ToString())
            .First()
            .GetCustomAttribute <DescriptionAttribute>()?
            .Description ?? string.Empty);
 }
示例#19
0
 /// <summary>
 /// 获取枚举值
 /// </summary>
 /// <param name="instance">枚举实例</param>
 public static int Value(this System.Enum instance)
 {
     if (instance == null)
     {
         return(0);
     }
     return(WXKJ.Framework.Helpers.Enum.GetValue(instance.GetType(), instance));
 }
 public GameObject GetSoldier(System.Enum type)
 {
     if (type.GetType() == typeof(Soldier))
     {
         return(AssetUtils.Instance.GetAsset(type.ToString()) as GameObject);
     }
     return(null);
 }
示例#21
0
        public static string GetDescription <T>(this System.Enum enumVal)
        {
            var type       = enumVal?.GetType();
            var memInfo    = type?.GetMember(enumVal?.ToString());
            var attributes = memInfo[0]?.GetCustomAttributes(typeof(EnumValueAsText), false);

            return((attributes?.Length > 0) ? ((EnumValueAsText)attributes[0])?.Value : null);
        }
示例#22
0
        /// <summary>
        /// Gets an attribute on an enum field value
        /// </summary>
        /// <typeparam name="T">The type of the attribute you want to retrieve</typeparam>
        /// <param name="enumVal">The enum value</param>
        /// <returns>The attribute of type T that exists on the enum value</returns>
        public static T GetAttributeOnEnum <T>(this System.Enum enumVal) where T : System.Attribute
        {
            var type       = enumVal.GetType();
            var memInfo    = type.GetTypeInfo().GetDeclaredField(enumVal.ToString());
            var attributes = memInfo.GetCustomAttributes(typeof(T), false);

            return((attributes.Count() > 0) ? (T)attributes.First() : null);
        }
示例#23
0
 /// <summary>
 /// 获取枚举描述,使用System.ComponentModel.Description特性设置描述
 /// </summary>
 /// <param name="instance">枚举实例</param>
 public static string Description(this System.Enum instance)
 {
     if (instance == null)
     {
         return(string.Empty);
     }
     return(WXKJ.Framework.Helpers.Enum.GetDescription(instance.GetType(), instance));
 }
示例#24
0
        public static T GetAttributeOfType <T>(this System.Enum enumVal) where T : System.Attribute
        {
            var type       = enumVal.GetType();
            var memInfo    = type.GetMember(enumVal.ToString());
            var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);

            return((attributes.Length > 0) ? (T)attributes[0] : null);
        }
        /// <summary>
        /// Validar se o valor que está no Enum foi definido corretamente
        /// </summary>
        /// <param name="value">Valor setado no Enum</param>
        /// <returns>Retorna se o Enum possuí valor válido.</returns>
        public static bool IsEnumValid(this System.Enum value)
        {
            if (System.Enum.IsDefined(value.GetType(), value))
            {
                return(true);
            }

            return(false);
        }
示例#26
0
        public static string Text(this System.Enum x)
        {
            var type        = x.GetType();
            var memberInfos = type.GetMember(x.ToString());
            var attributes  = memberInfos[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
            var description = ((DescriptionAttribute)attributes[0]).Description;

            return(description);
        }
示例#27
0
 /// <summary>
 /// 获取枚举类的特性标记
 /// </summary>
 /// <typeparam name="T">特性类型</typeparam>
 /// <param name="mananer">特性实例</param>
 /// <returns></returns>
 public static T GetFieldAttribute <T>(this System.Enum mananer) where T : System.Attribute
 {
     System.Attribute[] atts = mananer.GetType().GetField(mananer.ToString()).GetCustomAttributes(typeof(T), false) as System.Attribute[];
     if (atts == null || atts.Length == 0)
     {
         return(null);
     }
     return(atts[0] as T);
 }
        public static string ToStringValue(this System.Enum value)
        {
            var attributes = (StringValueAttribute[])value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(StringValueAttribute), false);

            if (attributes.Any())
                return attributes[0].Value;

            return value.ToString();
        }
示例#29
0
文件: pb_GUI.cs 项目: kallqvist/giles
        /**
         * A field for editing enum values
         */
        public static int EnumField(System.Enum value)
        {
            var values = System.Enum.GetValues(value.GetType());

            float v = (float)System.Convert.ToInt32(value);

            v = GUILayout.HorizontalSlider(v, 0, values.Length);

            return((int)v);
        }
示例#30
0
        private static void Debug_ValidateMask(System.Enum value, UInt32 mask)
        {
            Type   t       = value.GetType();
            UInt32 newmask = 0;

            foreach (int iVal in Enum.GetValues(t))
            {
                newmask = newmask | (UInt32)iVal;
            }
            System.Diagnostics.Debug.Assert(newmask == mask, "Mask not valid in IsEnumValid!");
        }