コード例 #1
0
 /// <summary>
 /// Disables a mask
 /// </summary>
 /// <param name="value"></param>
 /// <param name="flag"></param>
 public static void Disable(int value, int flag)
 {
     if (!FlagsHelper.IsFlagSet(value, flag))
     {
         value ^= flag;
     }
 }
コード例 #2
0
        public static string GetCombinedEnumValuesDescription(object value, Type t)
        {
            string description = null;

            try
            {
                description = value.ToString();

                MemberInfo[] members = t.GetMembers(BindingFlags.Static | BindingFlags.Public);

                ArrayList valuesSet = new ArrayList();
                Array     values    = Enum.GetValues(t);
                foreach (object enumValue in values)
                {
                    if (FlagsHelper.IsFlagSet((int)value, (int)enumValue))
                    {
                        valuesSet.Add(enumValue);
                    }
                }

                StringBuilder sb    = new StringBuilder();
                int           count = 0;
                foreach (MemberInfo memberInfo in members)
                {
                    foreach (object enumValue in valuesSet)
                    {
                        if (string.Compare(enumValue.ToString(), memberInfo.Name, false) == 0)
                        {
                            /// get the custom attributes, specifically looking for the description attribute
                            object[] attributes = memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
                            if (attributes != null)
                            {
                                /// who knows there may be more than one
                                foreach (DescriptionAttribute attribute in attributes)
                                {
                                    sb.AppendFormat("{0}{1}", attribute.Description, (count > 0 ? ", " : null));
                                }
                                count++;
                            }
                        }
                    }
                }
                return(sb.ToString());
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
            return(description);
        }