/[RomCheater]/trunk/RomCheater.Logging/logger.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/logger.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Logging/logger.cs	2012/06/03 19:47:47	265
+++ trunk/RomCheater.Logging/logger.cs	2012/06/03 20:40:36	269
@@ -61,8 +61,40 @@
         public static implicit operator EnumNameValuePair<TValue>(loggerflagsbase<TValue> t) { return new loggerflagsbase<TValue>(t); }
         public static implicit operator loggerflagsbase<TValue>(TValue t)
         {
-            foreach (KeyValuePair<TValue, EnumNameValuePair<TValue>> pair in value_pairs) { EnumNameValuePair<TValue> l = pair.Value; if (l.Value.Equals(t)) { return new loggerflagsbase<TValue>(l); } }
-            return loggerflagsbase<TValue>.NONE;
+            //foreach (KeyValuePair<TValue, EnumNameValuePair<TValue>> pair in value_pairs) { EnumNameValuePair<TValue> l = pair.Value; if (l.Value.Equals(t)) { return new loggerflagsbase<TValue>(l); } }
+            //return loggerflagsbase<TValue>.NONE;
+            List<string> pairs = new List<string>();
+            StringBuilder builder = new StringBuilder();
+            foreach (KeyValuePair<TValue, EnumNameValuePair<TValue>> pair in value_pairs)
+            {
+                EnumNameValuePair<TValue> enum_pair = pair.Value;
+                if (HasFlag(pair.Value, t) && enum_pair != NONE)
+                {
+                    pairs.Add(enum_pair);
+                }
+            }
+            if (pairs.Count == 0)
+            {
+                return NONE;
+            }
+            else
+            {
+                int count = 0;
+                foreach (string pair in pairs)
+                {
+                    if (count == 0)
+                    {
+                        builder.AppendLine(pair);
+                    }
+                    else
+                    {
+                        builder.AppendFormat(" | {0}",pair);
+                    }
+                    count++;
+                }
+                loggerflagsbase<TValue> rVal = new loggerflagsbase<TValue>(new EnumNameValuePair<TValue>(builder.ToString(), t));
+                return rVal;
+            }
         }
         public static implicit operator TValue(loggerflagsbase<TValue> t) { return t.CurrentValue.Value; }
         public static implicit operator string(loggerflagsbase<TValue> t) { return t.CurrentValue.Name; }
@@ -107,11 +139,18 @@
         {
             bool hasflag = false;
             TValue value = this.CurrentValue;
-            if (!(EnumNameValuePair<TValue>.bitwise_and(flag, value)).Equals(value))
+            if ((EnumNameValuePair<TValue>.bitwise_and(flag, value)).Equals(flag))
+                hasflag = true;
+            return hasflag;
+        }
+        public static bool HasFlag(TValue flag, TValue compare)
+        {
+            bool hasflag = false;
+            TValue value = compare;
+            if ((EnumNameValuePair<TValue>.bitwise_and(flag, value)).Equals(flag))
                 hasflag = true;
             return hasflag;
         }
-
         public static List<TValue> GetValues() { return value_pairs.Keys.ToList(); }
         public static List<string> GetNames() { return name_pairs.Keys.ToList(); }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22