public Kvp Mirror() { Kvp MyResult = new Kvp(); MyResult.AddByKey((int)1, new Kvp()); MyResult.AddByKey((int)2, new Kvp()); foreach (KeyValuePair <dynamic, dynamic> my_pair in Host) { if (MyResult[1].LacksKey(my_pair.Value)) { MyResult[1].AddByKey(my_pair.Value, my_pair.Key); } else { MyResult[2].AddByKey(my_pair.Key, my_pair.Value); } } return(MyResult); }
public Kvp Invert() { Kvp InvertedKvp = new Kvp(); foreach (KeyValuePair <dynamic, dynamic> myPair in Host.Reverse()) { InvertedKvp.AddByKey(myPair.Key, myPair.Value); } return(InvertedKvp); }
public Kvp Clone() { Kvp CloneKvp = new Kvp(); foreach (KeyValuePair <dynamic, dynamic> myPair in Host) { CloneKvp.AddByKey(myPair.Key, myPair.Value); } return(CloneKvp); }
public Kvp Cohorts(dynamic ArgKvp) { Kvp ResultKvp = new Kvp(); // VBA reports object not set error if the result kvps are not newed for (int i = 1; i <= 6; i++) { ResultKvp.AddByKey(i, new Kvp()); } // Process Kvp A foreach (KeyValuePair <dynamic, dynamic> myPair in Host) { // A plus unique in B ResultKvp[(int)Cohort.AllAandBOnly].AddByKey(myPair.Key, myPair.Value); if (ArgKvp.LacksKey(myPair.Key)) { // In A only or in B only ResultKvp[(int)Cohort.InAorInB].AddByKey(myPair.Key, myPair.Value); // In A only ResultKvp[(int)Cohort.Aonly].AddByKey(myPair.Key, myPair.Value); } else { // In A and In B ResultKvp[(int)Cohort.AandBSameValues].AddByKey(myPair.Key, myPair.Value); } } //Process Kvp B foreach (KVPair myPair in ArgKvp) { // B in A with different value if (!Host.ContainsKey(myPair.Key)) { ResultKvp[(int)Cohort.AllAandBOnly].AddByKey(myPair.Key, myPair.Value); ResultKvp[(int)Cohort.InAorInB].AddByKey(myPair.Key, myPair.Value); ResultKvp[(int)Cohort.Bonly].AddByKey(myPair.Key, myPair.Value); } else { var myHost = Host[myPair.Key]; var myTest = myPair.Value; if ((dynamic)myHost != (dynamic)myTest) { ResultKvp.GetItem((int)Cohort.AandBDifferentValues).AddByKey(myPair.Key, new Kvp()); ResultKvp.GetItem((int)Cohort.AandBDifferentValues).GetItem(myPair.Key).AddByIndex(myHost); ResultKvp.GetItem((int)Cohort.AandBDifferentValues).GetItem(myPair.Key).AddByIndex(myPair.Value); } } } return(ResultKvp); }
public dynamic SubSetByKeys(dynamic KeyArray) { Kvp MySubSet = new Kvp(); foreach (dynamic myItem in KeyArray) { if (this.Host.ContainsKey(myItem)) { MySubSet.AddByKey(myItem, Host[myItem]); } } return(MySubSet); }