ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.Logging/EnumNameValuePair.cs
(Generate patch)

Comparing trunk/RomCheater.Logging/EnumNameValuePair.cs (file contents):
Revision 812 by william, Tue Apr 15 14:52:10 2014 UTC vs.
Revision 814 by william, Tue Apr 15 15:58:50 2014 UTC

--- trunk/RomCheater.Logging/EnumNameValuePair.cs	2014/04/15 14:52:10	812
+++ trunk/RomCheater.Logging/EnumNameValuePair.cs	2014/04/15 15:58:50	814
@@ -1,184 +1,184 @@
-//using System;
-//using System.Collections.Generic;
-//using System.Linq;
-//using System.Text;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
 
-//namespace RomCheater.Logging
-//{
-//    public class EnumNameValuePair<TValue>
-//        where TValue : IConvertible
-//    {
-//        #region implicit operators
-//        //public static implicit operator EnumNameValuePair<TValue>(TValue o) { return new EnumNameValuePair<TValue>("", o); }
-//        public static implicit operator TValue(EnumNameValuePair<TValue> o) { return o.Value; }
-//        public static implicit operator string(EnumNameValuePair<TValue> o) { return o.Name; }
-//        public static TValue operator |(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return bitwise_or(x, y); }
-//        public static TValue operator &(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return bitwise_and(x, y); }
-//        public static bool operator ==(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return x.Value.Equals(y.Value); }
-//        public static bool operator !=(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return !x.Value.Equals(y.Value); }
-//        public override bool Equals(object obj)
-//        {
-//            EnumNameValuePair<TValue> t = (obj as EnumNameValuePair<TValue>);
-//            if (t == null) return false;
-//           return this.Value.Equals(t.Value);
-//        }
-//        public override int GetHashCode()
-//        {
-//            return base.GetHashCode();
-//        }
-//        #endregion
-//        public EnumNameValuePair() : this("") { }
-//        public EnumNameValuePair(string name) : this(name, default(TValue)) { }
-//        public EnumNameValuePair(string name, TValue value)
-//        {
-//            this.Name = name;
-//            this.Value = value;
-//        }
-//        public string Name { get; protected set; }
-//        public TValue Value { get; protected set; }
-//        public override string ToString()
-//        {
-//            return string.Format("[{0}: 0x{1:x8}]", Name.ToString(), Value);
-//        }
-//        private static TValue bitwise_or(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y)
-//        {
-//            #region bitwise code
-//            string type = (typeof(TValue).Name);
-//            if (type.ToLower() == "byte")
-//            {
-//                byte x1 = Convert.ToByte(x.Value);
-//                byte y1 = Convert.ToByte(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "sbyte")
-//            {
-//                sbyte x1 = Convert.ToSByte(x.Value);
-//                sbyte y1 = Convert.ToSByte(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int16")
-//            {
-//                short x1 = Convert.ToInt16(x.Value);
-//                short y1 = Convert.ToInt16(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint16")
-//            {
-//                ushort x1 = Convert.ToUInt16(x.Value);
-//                ushort y1 = Convert.ToUInt16(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int32")
-//            {
-//                int x1 = Convert.ToInt32(x.Value);
-//                int y1 = Convert.ToInt32(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint32")
-//            {
-//                uint x1 = Convert.ToUInt32(x.Value);
-//                uint y1 = Convert.ToUInt32(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int64")
-//            {
-//                long x1 = Convert.ToInt64(x.Value);
-//                long y1 = Convert.ToInt64(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint64")
-//            {
-//                ulong x1 = Convert.ToUInt64(x.Value);
-//                ulong y1 = Convert.ToUInt64(y.Value);
-//                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
-//            }
-//            else
-//            {
-//                throw new InvalidCastException(string.Format("Unable to cast values to type: {0}", type), new NotImplementedException(string.Format("Type: {0} has not been implemented", type)));
-//            }
-//            #endregion
-//        }
-//        private static TValue bitwise_and(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y)
-//        {
-//            #region bitwise code
-//            string type = (typeof(TValue).Name);
-//            if (type.ToLower() == "byte")
-//            {
-//                byte x1 = Convert.ToByte(x.Value);
-//                byte y1 = Convert.ToByte(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "sbyte")
-//            {
-//                sbyte x1 = Convert.ToSByte(x.Value);
-//                sbyte y1 = Convert.ToSByte(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int16")
-//            {
-//                short x1 = Convert.ToInt16(x.Value);
-//                short y1 = Convert.ToInt16(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint16")
-//            {
-//                ushort x1 = Convert.ToUInt16(x.Value);
-//                ushort y1 = Convert.ToUInt16(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int32")
-//            {
-//                int x1 = Convert.ToInt32(x.Value);
-//                int y1 = Convert.ToInt32(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint32")
-//            {
-//                uint x1 = Convert.ToUInt32(x.Value);
-//                uint y1 = Convert.ToUInt32(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "int64")
-//            {
-//                long x1 = Convert.ToInt64(x.Value);
-//                long y1 = Convert.ToInt64(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else if (type.ToLower() == "uint64")
-//            {
-//                ulong x1 = Convert.ToUInt64(x.Value);
-//                ulong y1 = Convert.ToUInt64(y.Value);
-//                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
-//            }
-//            else
-//            {
-//                throw new InvalidCastException(string.Format("Unable to cast values to type: {0}", type), new NotImplementedException(string.Format("Type: {0} has not been implemented", type)));
-//            }
-//            #endregion
-//        }
+namespace RomCheater.Logging
+{
+    internal class EnumNameValuePair<TValue>
+        where TValue : IConvertible
+    {
+        #region implicit operators
+        //public static implicit operator EnumNameValuePair<TValue>(TValue o) { return new EnumNameValuePair<TValue>("", o); }
+        public static implicit operator TValue(EnumNameValuePair<TValue> o) { return o.Value; }
+        public static implicit operator string(EnumNameValuePair<TValue> o) { return o.Name; }
+        public static TValue operator |(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return bitwise_or(x, y); }
+        public static TValue operator &(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return bitwise_and(x, y); }
+        public static bool operator ==(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return x.Value.Equals(y.Value); }
+        public static bool operator !=(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y) { return !x.Value.Equals(y.Value); }
+        public override bool Equals(object obj)
+        {
+            EnumNameValuePair<TValue> t = (obj as EnumNameValuePair<TValue>);
+            if (t == null) return false;
+            return this.Value.Equals(t.Value);
+        }
+        public override int GetHashCode()
+        {
+            return base.GetHashCode();
+        }
+        #endregion
+        public EnumNameValuePair() : this("") { }
+        public EnumNameValuePair(string name) : this(name, default(TValue)) { }
+        public EnumNameValuePair(string name, TValue value)
+        {
+            this.Name = name;
+            this.Value = value;
+        }
+        public string Name { get; protected set; }
+        public TValue Value { get; protected set; }
+        public override string ToString()
+        {
+            return string.Format("[{0}: 0x{1:x8}]", Name.ToString(), Value);
+        }
+        private static TValue bitwise_or(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y)
+        {
+            #region bitwise code
+            string type = (typeof(TValue).Name);
+            if (type.ToLower() == "byte")
+            {
+                byte x1 = Convert.ToByte(x.Value);
+                byte y1 = Convert.ToByte(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "sbyte")
+            {
+                sbyte x1 = Convert.ToSByte(x.Value);
+                sbyte y1 = Convert.ToSByte(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int16")
+            {
+                short x1 = Convert.ToInt16(x.Value);
+                short y1 = Convert.ToInt16(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint16")
+            {
+                ushort x1 = Convert.ToUInt16(x.Value);
+                ushort y1 = Convert.ToUInt16(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int32")
+            {
+                int x1 = Convert.ToInt32(x.Value);
+                int y1 = Convert.ToInt32(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint32")
+            {
+                uint x1 = Convert.ToUInt32(x.Value);
+                uint y1 = Convert.ToUInt32(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int64")
+            {
+                long x1 = Convert.ToInt64(x.Value);
+                long y1 = Convert.ToInt64(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint64")
+            {
+                ulong x1 = Convert.ToUInt64(x.Value);
+                ulong y1 = Convert.ToUInt64(y.Value);
+                return (TValue)Convert.ChangeType(x1 | y1, typeof(TValue));
+            }
+            else
+            {
+                throw new InvalidCastException(string.Format("Unable to cast values to type: {0}", type), new NotImplementedException(string.Format("Type: {0} has not been implemented", type)));
+            }
+            #endregion
+        }
+        private static TValue bitwise_and(EnumNameValuePair<TValue> x, EnumNameValuePair<TValue> y)
+        {
+            #region bitwise code
+            string type = (typeof(TValue).Name);
+            if (type.ToLower() == "byte")
+            {
+                byte x1 = Convert.ToByte(x.Value);
+                byte y1 = Convert.ToByte(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "sbyte")
+            {
+                sbyte x1 = Convert.ToSByte(x.Value);
+                sbyte y1 = Convert.ToSByte(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int16")
+            {
+                short x1 = Convert.ToInt16(x.Value);
+                short y1 = Convert.ToInt16(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint16")
+            {
+                ushort x1 = Convert.ToUInt16(x.Value);
+                ushort y1 = Convert.ToUInt16(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int32")
+            {
+                int x1 = Convert.ToInt32(x.Value);
+                int y1 = Convert.ToInt32(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint32")
+            {
+                uint x1 = Convert.ToUInt32(x.Value);
+                uint y1 = Convert.ToUInt32(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "int64")
+            {
+                long x1 = Convert.ToInt64(x.Value);
+                long y1 = Convert.ToInt64(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else if (type.ToLower() == "uint64")
+            {
+                ulong x1 = Convert.ToUInt64(x.Value);
+                ulong y1 = Convert.ToUInt64(y.Value);
+                return (TValue)Convert.ChangeType(x1 & y1, typeof(TValue));
+            }
+            else
+            {
+                throw new InvalidCastException(string.Format("Unable to cast values to type: {0}", type), new NotImplementedException(string.Format("Type: {0} has not been implemented", type)));
+            }
+            #endregion
+        }
 
-//        internal static TValue bitwise_or(TValue x, TValue y)
-//        {
-//            return bitwise_or(new EnumNameValuePair<TValue>("",x), new EnumNameValuePair<TValue>("",y));
-//        }
-//        public static TValue bitwise_or(params EnumNameValuePair<TValue>[] values)
-//        {
-//            if (!(values.Length > 1 )) { throw new InvalidOperationException("bitwise_or must have at least two operands"); }
-//            TValue value = default(TValue);
-//            foreach (EnumNameValuePair<TValue> v in values) { value = bitwise_or(value, v.Value); }
-//            return value;
-//        }
+        internal static TValue bitwise_or(TValue x, TValue y)
+        {
+            return bitwise_or(new EnumNameValuePair<TValue>("", x), new EnumNameValuePair<TValue>("", y));
+        }
+        public static TValue bitwise_or(params EnumNameValuePair<TValue>[] values)
+        {
+            if (!(values.Length > 1)) { throw new InvalidOperationException("bitwise_or must have at least two operands"); }
+            TValue value = default(TValue);
+            foreach (EnumNameValuePair<TValue> v in values) { value = bitwise_or(value, v.Value); }
+            return value;
+        }
 
-//        internal static TValue bitwise_and(TValue x, TValue y)
-//        {
-//            return bitwise_and(new EnumNameValuePair<TValue>("", x), new EnumNameValuePair<TValue>("", y));
-//        }
-//        public static TValue bitwise_and(params EnumNameValuePair<TValue>[] values)
-//        {
-//            if (!(values.Length > 1)) { throw new InvalidOperationException("bitwise_and must have at least two operands"); }
-//            TValue value = default(TValue);
-//            foreach (EnumNameValuePair<TValue> v in values) { value = bitwise_and(value, v.Value); }
-//            return value;
-//        }
-//    }
-//}
+        internal static TValue bitwise_and(TValue x, TValue y)
+        {
+            return bitwise_and(new EnumNameValuePair<TValue>("", x), new EnumNameValuePair<TValue>("", y));
+        }
+        public static TValue bitwise_and(params EnumNameValuePair<TValue>[] values)
+        {
+            if (!(values.Length > 1)) { throw new InvalidOperationException("bitwise_and must have at least two operands"); }
+            TValue value = default(TValue);
+            foreach (EnumNameValuePair<TValue> v in values) { value = bitwise_and(value, v.Value); }
+            return value;
+        }
+    }
+}