示例#1
0
        public static bool Has <T>(this Enum value, T check)
        {
            Type   type   = value.GetType();
            _Value value2 = new _Value(check, type);

            if (value2.Signed is long)
            {
                return((Convert.ToInt64(value) & value2.Signed.Value) == value2.Signed.Value);
            }
            if (value2.Unsigned is ulong)
            {
                return((Convert.ToUInt64(value) & value2.Unsigned.Value) == value2.Unsigned.Value);
            }
            return(false);
        }
示例#2
0
        public static bool Has <T>(this Enum value, T check)
        {
            var type = value.GetType();
            var obj  = new _Value(check, type);

            if (obj.Signed.HasValue)
            {
                return((Convert.ToInt64(value) & obj.Signed.Value) == obj.Signed.Value);
            }
            if (obj.Unsigned.HasValue)
            {
                return(((long)Convert.ToUInt64(value) & (long)obj.Unsigned.Value) ==
                       (long)obj.Unsigned.Value);
            }
            return(false);
        }
示例#3
0
        public static T Remove <T>(this Enum value, T remove)
        {
            var type = value.GetType();
            var obj1 = (object)value;
            var obj2 = new _Value(remove, type);

            if (obj2.Signed.HasValue)
            {
                obj1 = Convert.ToInt64(value) & ~obj2.Signed.Value;
            }
            else if (obj2.Unsigned.HasValue)
            {
                obj1 = (ulong)((long)Convert.ToUInt64(value) & ~(long)obj2.Unsigned.Value);
            }
            return((T)Enum.Parse(type, obj1.ToString()));
        }
示例#4
0
        public static T Include <T>(this Enum value, T append)
        {
            var type = value.GetType();
            var obj1 = value;
            var obj2 = new _Value(append, type);

            if (obj2.Signed.HasValue)
            {
                obj1 = (Enum)(object)(Convert.ToInt64(value) | obj2.Signed.Value);
            }
            else if (obj2.Unsigned.HasValue)
            {
                obj1 = (Enum)(object)(ulong)((long)Convert.ToUInt64(value) | (long)obj2.Unsigned.Value);
            }
            return((T)Enum.Parse(type, obj1.ToString()));
        }
示例#5
0
        public static T Remove <T>(this Enum value, T remove)
        {
            Type   type   = value.GetType();
            object obj    = value;
            _Value value2 = new _Value(remove, type);

            if (value2.Signed is long)
            {
                obj = (Convert.ToInt64(value) & ~value2.Signed.Value);
            }
            else if (value2.Unsigned is ulong)
            {
                obj = (Convert.ToUInt64(value) & ~value2.Unsigned.Value);
            }
            return((T)Enum.Parse(type, obj.ToString()));
        }
        public static T Include <T>(this Enum value, T append)
        {
            Type   type   = value.GetType();
            object obj    = value;
            _Value value2 = new _Value(append, type);

            if (value2.Signed.HasValue)
            {
                obj = (Convert.ToInt64(value) | value2.Signed.Value);
            }
            else if (value2.Unsigned.HasValue)
            {
                obj = (Convert.ToUInt64(value) | value2.Unsigned.Value);
            }
            return((T)Enum.Parse(type, obj.ToString()));
        }
示例#7
0
        static T Relegate <T>(Enum value, T remove)
        {
            Type type = value.GetType();

            //determine the values
            object result = value;
            _Value parsed = new _Value(remove, type);

            if (parsed.Signed is long)
            {
                result = Convert.ToInt64(value) & ~(long)parsed.Signed;
            }
            else if (parsed.Unsigned is ulong)
            {
                result = Convert.ToUInt64(value) & ~(ulong)parsed.Unsigned;
            }

            //return the final value
            return((T)Enum.Parse(type, result.ToString()));
        }
示例#8
0
        /// <summary>
        /// Includes an enumerated type and returns the new value
        /// </summary>
        public static T Include <T>(this Enum value, T append)
        {
            Type type = value.GetType();

            //determine the values
            object result = value;
            _Value parsed = new _Value(append, type);

            if (parsed.Signed is long)
            {
                result = Convert.ToInt64(value) | (long)parsed.Signed;
            }
            else if (parsed.Unsigned is ulong)
            {
                result = Convert.ToUInt64(value) | (ulong)parsed.Unsigned;
            }

            //return the final value
            return((T)Enum.Parse(type, result.ToString()));
        }
示例#9
0
        /// <summary>
        /// Checks if an enumerated type contains a value
        /// </summary>
        public static bool Has <T>(this Enum value, T check)
        {
            Type type = value.GetType();

            _Value parsed = new _Value(check, type);

            if (parsed.Signed is long)
            {
                return((Convert.ToInt64(value) &
                        (long)parsed.Signed) == (long)parsed.Signed);
            }
            else if (parsed.Unsigned is ulong)
            {
                return((Convert.ToUInt64(value) &
                        (ulong)parsed.Unsigned) == (ulong)parsed.Unsigned);
            }
            else
            {
                return(false);
            }
        }