Anonymous avatar Anonymous committed 3ba5843

คิดไม่ออก

Comments (0)

Files changed (1)

Usually/Resolve.cs

             m.StringKey(name, getKey, sequence, (s) => s.StartsWith(prefix));
         }
     }
-    public class MetaInfoBuilder<T> : IMetaBuilder<T>, IMetaInfo<T>
+    class ColumnsDef<T>
     {
-        #region Nested Classes
-        private class ColumnsDef
+        private IList<string> names = new List<string>();
+        private IDictionary<string, Func<T, object>> getters = new Dictionary<string, Func<T, object>>();
+        protected void Add(string name, Func<T, object> getter)
         {
-            private IList<string> names = new List<string>();
-            private IDictionary<string, Func<T, object>> getters = new Dictionary<string, Func<T, object>>();
-            protected void Add(string name, Func<T, object> getter)
+            if (this.getters.ContainsKey(name)) throw new Exception("Duplicate name: " + name);
+            this.getters.Add(name, getter);
+            this.names.Add(name);
+        }
+        public int Count { get { return this.names.Count; } }
+        public IEnumerable<string> Names { get { return this.names; } }
+        public void ForEach(T obj, Action<string, object> action)
+        {
+            for (int i = 0; i < this.names.Count; i++)
+                action(this.names[i], this.getters[this.names[i]](obj));
+        }
+        public void ForEachChange(T o, T n, Action<string, object, object> action)
+        {
+            for (int i = 0; i < this.names.Count; i++)
             {
-                if (this.getters.ContainsKey(name)) throw new Exception("Duplicate name: " + name);
-                this.getters.Add(name, getter);
-                this.names.Add(name);
-            }
-            public void ForEach(T obj, Action<string, object> action)
-            {
-                for (int i = 0; i < this.names.Count; i++)
-                    action(this.names[i], this.getters[this.names[i]](obj));
-            }
-            public void ForEachChange(T o, T n, Action<string, object, object> action)
-            {
-                for (int i = 0; i < this.names.Count; i++)
-                {
-                    var ov = this.getters[this.names[i]](o);
-                    var nv = this.getters[this.names[i]](n);
-                    if (!EqualityComparer<object>.Default.Equals(ov, nv))
-                        action(this.names[i], ov, nv);
-                }
-            }
-            public object[] GetFrom(T obj)
-            {
-                var values = new object[this.names.Count];
-                for (int i = 0; i < this.names.Count; i++)
-                    values[i] = this.getters[this.names[i]](obj);
-                return values;
-            }
-            public object GetFrom(T obj, string name)
-            {
-                return this.getters[name](obj);
-            }
-            public object[] GetFrom(IDictionary<string, object> dict)
-            {
-                var values = new object[this.names.Count];
-                for (int i = 0; i < this.names.Count; i++)
-                    values[i] = dict[this.names[i]];
-                return values;
+                var ov = this.getters[this.names[i]](o);
+                var nv = this.getters[this.names[i]](n);
+                if (!EqualityComparer<object>.Default.Equals(ov, nv))
+                    action(this.names[i], ov, nv);
             }
         }
-        private class KeysDef: ColumnsDef, IKeyBuilder<T>
+        public object[] GetFrom(T obj)
         {
-            private IDictionary<string, Func<object, string>> generators = new Dictionary<string, Func<object, string>>();
-            public void Add(string name, Func<T, object> getKey, Func<object, string> generator = null)
-            {
-                base.Add(name, getKey);
-                if (generator != null) this.generators.Add(name, generator);
-            }
-            void IKeyBuilder<T>.Key(string name, Func<T, object> getKey, Func<object, string> generator)
-            {
-                this.Add(name, getKey, generator);
-            }
-            public string GeneratorExpr(string name, object value)
-            {
-                Func<object, string> g = null;
-                if (! this.generators.TryGetValue(name, out g)) return null;
-                return g(value);
-            }
+            var values = new object[this.names.Count];
+            for (int i = 0; i < this.names.Count; i++)
+                values[i] = this.getters[this.names[i]](obj);
+            return values;
         }
-        private class ValuesDef : ColumnsDef
+        public object GetFrom(T obj, string name)
         {
-            public new void Add(string name, Func<T, object> getValue)
-            {
-                base.Add(name, getValue);
-            }
+            return this.getters[name](obj);
         }
-        #endregion
-
-        #region Private Fields
-        private string tableName;
-        private KeysDef keys = new KeysDef();
-        private IDictionary<string, KeysDef> extraKeys = new Dictionary<string, KeysDef>();
-        private ValuesDef values = new ValuesDef();
-        private IList<string> refList = new List<string>();
-        private string group = null;
-        #endregion
-
-        #region Implement IMetaBuilder<T>
+        public object[] GetFrom(IDictionary<string, object> dict)
+        {
+            var values = new object[this.names.Count];
+            for (int i = 0; i < this.names.Count; i++)
+                values[i] = dict[this.names[i]];
+            return values;
+        }
+    }
+    class KeysDef<T> : ColumnsDef<T>, IKeyBuilder<T>
+    {
+        private IDictionary<string, Func<object, string>> generators = new Dictionary<string, Func<object, string>>();
+        public void Add(string name, Func<T, object> getKey, Func<object, string> generator = null)
+        {
+            base.Add(name, getKey);
+            if (generator != null) this.generators.Add(name, generator);
+        }
+        void IKeyBuilder<T>.Key(string name, Func<T, object> getKey, Func<object, string> generator)
+        {
+            this.Add(name, getKey, generator);
+        }
+        public string GeneratorExpr(string name, object value)
+        {
+            Func<object, string> g = null;
+            if (!this.generators.TryGetValue(name, out g)) return null;
+            return g(value);
+        }
+    }
+    class ValuesDef<T> : ColumnsDef<T>
+    {
+        public new void Add(string name, Func<T, object> getValue)
+        {
+            base.Add(name, getValue);
+        }
+    }
+    class MetaInfoBuilderBase<T> : IMetaBuilder<T>
+    {
+        protected string tableName;
+        protected KeysDef<T> keys = new KeysDef<T>();
+        protected IDictionary<string, KeysDef<T>> extraKeys = new Dictionary<string, KeysDef<T>>();
+        protected ValuesDef<T> values = new ValuesDef<T>();
+        protected IList<string> refList = new List<string>();
+        protected string group = null;
         void IMetaBuilder<T>.Table(string name) { this.tableName = name; }
         void IKeyBuilder<T>.Key(string name, Func<T, object> getKey, Func<object, string> generator)
         {
         }
         IKeyBuilder<T> IMetaBuilder<T>.ExtraKey(string group)
         {
-            KeysDef r = null;
+            KeysDef<T> r = null;
             if (this.extraKeys.TryGetValue(group, out r)) return r;
-            r = new KeysDef();
+            r = new KeysDef<T>();
             this.extraKeys.Add(group, r);
             return r;
         }
         {
             this.group = @group;
         }
-        #endregion
-
-        #region Implement IMetaInfo<T>
+    }
+    class MetaInfoBuilder<T> : MetaInfoBuilderBase<T>, IMetaInfo<T>
+    {
         string IMetaInfo<T>.TableName { get { return this.tableName; } }
         object[] IMetaInfo<T>.GetKey(T obj)
         {
             for (int i = 0; i < actualKey.Length; i++)
                 dict[this.refList[i]] = actualKey[i];
         }
-        #endregion
     }
     public delegate void Meta<T>(IMetaBuilder<T> m);
     abstract class AbstractReconciler<OldT, NewT>
     {
         private class GenericItemList
         {
+            private class InnerInfoBuilder : MetaInfoBuilderBase<T>, IMetaInfo<object[]>
+            {
+                private IList<string> extraKeysNames = null;
+                string IMetaInfo<object[]>.TableName 
+                {
+                    get
+                    {
+                        return this.tableName;
+                    }
+                }
+                object[] IMetaInfo<object[]>.GetKey(object[] obj)
+                {
+                    return obj.Take(this.keys.Count).ToArray();
+                }
+                object[] IMetaInfo<object[]>.GetKey(IDictionary<string, object> dict)
+                {
+                    return this.keys.GetFrom(dict);
+                }
+                object[] IMetaInfo<object[]>.GetExtraKey(string group, object[] obj)
+                {
+                    int start = 0;
+                    foreach (var g in this.extraKeys.Keys.OrderBy(x => x))
+                    {
+                    }
+                    return null;
+                }
+                object[] IMetaInfo<object[]>.GetExtraKey(string group, IDictionary<string, object> dict)
+                {
+                    return null;
+                }
+                string IMetaInfo<object[]>.GeneratorExpr(string name, object value)
+                {
+                    return null;
+                }
+                void IMetaInfo<object[]>.ForEachKey(object[] obj, Action<string, object> action)
+                {
+                }
+                void IMetaInfo<object[]>.ForEachExtraKey(string group, object[] obj, Action<string, object> action)
+                {
+                }
+                void IMetaInfo<object[]>.ForEachInsertValue(object[] obj, Action<string, object> action)
+                {
+                }
+                void IMetaInfo<object[]>.ForEachValueChange(object[] o, object[] n, Action<string, object, object> action)
+                {
+                }
+                string IMetaInfo<object[]>.MasterKeyGroup
+                {
+                    get
+                    {
+                        return null;
+                    }
+                }
+                object[] IMetaInfo<object[]>.GetMasterRef(object[] obj)
+                {
+                    return null;
+                }
+                void IMetaInfo<object[]>.SetActualMasterKey(IDictionary<string, object> dict, object[] actualKey)
+                {
+                }
+            }
             private IMetaInfo<T> info = null;
             private List<object[]> items = new List<object[]>();
             private Dictionary<string, int> indexByName = null;
             {
                 this.items.ForEach(action);
             }
+            public static Meta<object[]> GetMeta(Meta<T> inner)
+            {
+              //      public delegate void Meta<T>(IMetaBuilder<T> m);
+                return m => {
+                    //inner(
+                };
+            //Action<object[]>
+            }
         }
         public class SettlerItem
         {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.