Commits

Anonymous committed 1825773

interface based

Comments (0)

Files changed (2)

Usually/Resolve.cs

     {
         public InsertRecord() : base() { }
         public InsertRecord(string tableName) : base(tableName) { }
-        public Dictionary<string, object> Values = new Dictionary<string, object>();
+        public IDictionary<string, object> Values = new Dictionary<string, object>();
         public InsertRecord CloneInsert()
         {
             var r = new InsertRecord();
             this.AtLeastOne = true;
             this.AtMostOne = true;
         }
-        public Dictionary<string, object> Keys = new Dictionary<string, object>();
-        public Dictionary<string, object> Values = new Dictionary<string, object>();
+        public IDictionary<string, object> Keys = new Dictionary<string, object>();
+        public IDictionary<string, object> Values = new Dictionary<string, object>();
         public UpdateRecord CloneUpdate()
         {
             var r = new UpdateRecord();
             this.AtLeastOne = true;
             this.AtMostOne = true;
         }
-        public Dictionary<string, object> Keys = new Dictionary<string, object>();
+        public IDictionary<string, object> Keys = new Dictionary<string, object>();
         public UpdateRecord CloneDelete()
         {
             var r = new UpdateRecord();
     {
         string TableName { get; }
         object[] GetKey(T obj);
-        object[] GetKey(Dictionary<string, object> dict);
+        object[] GetKey(IDictionary<string, object> dict);
         object[] GetExtraKey(string group, T obj);
-        object[] GetExtraKey(string group, Dictionary<string, object> dict);
+        object[] GetExtraKey(string group, IDictionary<string, object> dict);
         string GeneratorExpr(string name, object value);
         void ForEachKey(T obj, Action<string, object> action);
         void ForEachExtraKey(string group, T obj, Action<string, object> action);
         void ForEachValueChange(T o, T n, Action<string, object, object> action);
         string MasterKeyGroup { get; }
         object[] GetMasterRef(T obj);
-        void SetActualMasterKey(Dictionary<string, object> dict, object[] actualKey);
+        void SetActualMasterKey(IDictionary<string, object> dict, object[] actualKey);
     }
     public static class MetaBuilderExtension
     {
         #region Nested Classes
         private class ColumnsDef
         {
-            private List<string> names = new List<string>();
-            private Dictionary<string, Func<T, object>> getters = new Dictionary<string, Func<T, object>>();
+            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);
             {
                 return this.getters[name](obj);
             }
-            public object[] GetFrom(Dictionary<string, object> dict)
+            public object[] GetFrom(IDictionary<string, object> dict)
             {
                 var values = new object[this.names.Count];
                 for (int i = 0; i < this.names.Count; i++)
         }
         private class KeysDef: ColumnsDef, IKeyBuilder<T>
         {
-            private Dictionary<string, Func<object, string>> generators = new Dictionary<string, Func<object, string>>();
+            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);
         #region Private Fields
         private string tableName;
         private KeysDef keys = new KeysDef();
-        private Dictionary<string, KeysDef> extraKeys = new Dictionary<string, KeysDef>();
+        private IDictionary<string, KeysDef> extraKeys = new Dictionary<string, KeysDef>();
         private ValuesDef values = new ValuesDef();
-        private List<string> refList = new List<string>();
+        private IList<string> refList = new List<string>();
         private string group = null;
         #endregion
 
         {
             return this.keys.GetFrom(obj);
         }
-        object[] IMetaInfo<T>.GetKey(Dictionary<string, object> dict)
+        object[] IMetaInfo<T>.GetKey(IDictionary<string, object> dict)
         {
             return this.keys.GetFrom(dict);
         }
         {
             return this.extraKeys[group].GetFrom(obj);
         }
-        object[] IMetaInfo<T>.GetExtraKey(string group, Dictionary<string, object> dict)
+        object[] IMetaInfo<T>.GetExtraKey(string group, IDictionary<string, object> dict)
         {
             return this.extraKeys[group].GetFrom(dict);
         }
             }
             return r;
         }
-        void IMetaInfo<T>.SetActualMasterKey(Dictionary<string, object> dict, object[] actualKey)
+        void IMetaInfo<T>.SetActualMasterKey(IDictionary<string, object> dict, object[] actualKey)
         {
             if (this.refList.Count <= 0) return;
             for (int i = 0; i < actualKey.Length; i++)
         private IMetaInfo<T> info = null;
         private IEnumerable<T> olds = null;
         private IEnumerable<T> news = null;
-        private Dictionary<object[], T> oldLookup = null;
-        private Dictionary<object[], T> newLookup = null;
+        private IDictionary<object[], T> oldLookup = null;
+        private IDictionary<object[], T> newLookup = null;
         public Reconciler(IMetaInfo<T> info, IEnumerable<T> olds, IEnumerable<T> news)
         {
             this.info = @info;
             this.oldLookup = CreateLookup(this.info, @olds);
             this.newLookup = CreateLookup(this.info, @news);
         }
-        private static Dictionary<object[], T> CreateLookup(IMetaInfo<T> info, IEnumerable<T> list)
+        private static IDictionary<object[], T> CreateLookup(IMetaInfo<T> info, IEnumerable<T> list)
         {
             var r = new Dictionary<object[], T>(JonSkeet.ArrayEqualityComparer<object>.Default);
             foreach (var o in list) r.Add(info.GetKey(o), o);
     public class Resolver
     {
         public const int DEFAULT_DUMMY_START = -1;
-        private List<IResolverItem> items = new List<IResolverItem>();
+        private IList<IResolverItem> items = new List<IResolverItem>();
         private Func<string, object> generator = null;
         public Resolver(Func<string, object> generator = null)
         {
             return r.Resolve();
         }
     }
-    interface IResolverItem
+    public interface IResolverItem
     {
         string Group { get; }
         IEnumerable<TransactionRecord> ResolveForRoot();
     public class ResolverItem<T> : IResolverItem 
     {
         private Resolver host = null;
-        private List<IResolverItem> items = new List<IResolverItem>();
+        private IList<IResolverItem> items = new List<IResolverItem>();
         private IMetaInfo<T> info = null;
         private string group = null;
         private IEnumerable<T> olds = null;
         private IEnumerable<T> news = null;
-        private Dictionary<object[], List<TransactionJournal<T>>> _journals = null;
-        protected Dictionary<object[], List<TransactionJournal<T>>> CreateJournals()
+        private IDictionary<object[], IList<TransactionJournal<T>>> _journals = null;
+        protected IDictionary<object[], IList<TransactionJournal<T>>> CreateJournals()
         {
-            var r = new Dictionary<object[], List<TransactionJournal<T>>>(JonSkeet.ArrayEqualityComparer<object>.Default);
+            var r = new Dictionary<object[], IList<TransactionJournal<T>>>(JonSkeet.ArrayEqualityComparer<object>.Default);
             var reconciler = new Reconciler<T>(this.info, this.olds, this.news);
             foreach (var j in reconciler.ReconcileNonDelete())
             {
                 var k = this.info.GetMasterRef(j.New);
-                List<TransactionJournal<T>> list = null;
+                IList<TransactionJournal<T>> list = null;
                 if (! r.TryGetValue(k, out list)) 
                 {
                     list = new List<TransactionJournal<T>>();
             foreach (var j in reconciler.ReconcileDelete())
             {
                 var k = this.info.GetMasterRef(j.Old);
-                List<TransactionJournal<T>> list = null;
+                IList<TransactionJournal<T>> list = null;
                 if (! r.TryGetValue(k, out list)) 
                 {
                     list = new List<TransactionJournal<T>>();
         protected IEnumerable<TransactionJournal<T>> GetJournals(object[] masterKey)
         {
             if (this._journals == null) this._journals = this.CreateJournals();
-            List<TransactionJournal<T>> r = null;
+            IList<TransactionJournal<T>> r = null;
             if (!this._journals.TryGetValue(masterKey, out r)) return Enumerable.Empty<TransactionJournal<T>>();
             return r;
         }
                  ? this.info.GetKey(obj)
                  : this.info.GetExtraKey(i.Group, obj);
         }
-        private object[] GetKeyForDetail(IResolverItem i, Dictionary<string, object> dict)
+        private object[] GetKeyForDetail(IResolverItem i, IDictionary<string, object> dict)
         {
             return String.IsNullOrEmpty(i.Group)
                  ? this.info.GetKey(dict)
         }
         protected void SetActualMasterKey(TransactionRecord t, object[] actualKey)
         {
-            Dictionary<string, object> dict = null;
+            IDictionary<string, object> dict = null;
             if (t is InsertRecord) dict = (t as InsertRecord).Values;
             if (t is UpdateRecord) dict = (t as InsertRecord).Values;
             if (dict == null) throw new Exception("Unexpect type: " + t.GetType().Name);
             }
         }
     }
+    public class Settler<T>
+    {
+        public IResolverItem Add(string name, Meta<T> meta)
+        {
+            return null;
+        }
+        public void Load(Func<string, IEnumerable<T>> data)
+        {
+        }
+        public IEnumerable<TransactionRecord> Resolve()
+        {
+            return null;
+        }
+    }
 }

UsuallyTests/TestResolve.cs

             list.Add(master);
             act(master);
         }
-        public static void AssertInsert(TransactionRecord t, string tableName, Action<Dictionary<string, object>> build)
+        public static void AssertInsert(TransactionRecord t, string tableName, Action<IDictionary<string, object>> build)
         {
             Assert.IsInstanceOf(typeof(InsertRecord), t);
             var ins = t as InsertRecord;
             foreach (var i in d)
                 Assert.AreEqual(i.Value, ins.Values[i.Key]);
         }
-        public static void AssertUpdate(TransactionRecord t, string tableName, string keyName, object keyValue, Action<Dictionary<string, object>> build)
+        public static void AssertUpdate(TransactionRecord t, string tableName, string keyName, object keyValue, Action<IDictionary<string, object>> build)
         {
             Assert.IsInstanceOf(typeof(UpdateRecord), t);
             var upd = t as UpdateRecord;
             Assert.AreEqual(1, del.Keys.Count);
             Assert.AreEqual(keyValue, del.Keys[keyName]);
         }
-        public static void AssertNextInsert(IEnumerator<TransactionRecord> records, string tableName, Action<Dictionary<string, object>> build)
+        public static void AssertNextInsert(IEnumerator<TransactionRecord> records, string tableName, Action<IDictionary<string, object>> build)
         {
             Assert.True(records.MoveNext());
             AssertInsert(records.Current, tableName, build);
         }
-        public static void AssertNextUpdate(IEnumerator<TransactionRecord> records, string tableName, string keyName, object keyValue, Action<Dictionary<string, object>> build)
+        public static void AssertNextUpdate(IEnumerator<TransactionRecord> records, string tableName, string keyName, object keyValue, Action<IDictionary<string, object>> build)
         {
             Assert.True(records.MoveNext());
             AssertUpdate(records.Current, tableName, keyName, keyValue, build);