Exemple #1
0
        public Kvp Invert()
        {
            Kvp InvertedKvp = new Kvp();

            foreach (KeyValuePair <dynamic, dynamic> myPair in Host.Reverse())
            {
                InvertedKvp.AddByKey(myPair.Key, myPair.Value);
            }
            return(InvertedKvp);
        }
Exemple #2
0
        public Kvp Clone()
        {
            Kvp CloneKvp = new Kvp();

            foreach (KeyValuePair <dynamic, dynamic> myPair in Host)
            {
                CloneKvp.AddByKey(myPair.Key, myPair.Value);
            }
            return(CloneKvp);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void AddByKeyFromTable(dynamic table, bool CopyKeys = false, bool byColumn = false)
        {
            const int RowDimension = 0;
            const int ColDimension = 1;

            if (table.Rank != 2)
            {
                throw new ArgumentException("Kvp:AddByKeyFromTable: Two dimensional array expected");
            }

            int rowFirst = table.GetLowerBound(RowDimension);
            int rowLast  = table.GetUpperBound(RowDimension);
            int colFirst = table.GetLowerBound(ColDimension);
            int colLast  = table.GetUpperBound(ColDimension);

            if (byColumn)
            {
                for (int ThisColumn = colFirst; ThisColumn <= colLast; ThisColumn++)
                {
                    Kvp currentRow = new Kvp();
                    if (!CopyKeys)
                    {
                        rowFirst += 1;
                    }
                    for (int ThisRow = rowFirst; ThisRow <= rowLast; ThisRow++)
                    {
                        currentRow.AddByIndex(table[ThisRow, ThisColumn]);
                    }
                    Host.Add(table[0, ThisColumn], currentRow);
                }
            }
            else
            {
                for (int ThisRow = rowFirst; ThisRow <= rowLast; ThisRow++)
                {
                    Kvp currentCol = new Kvp();
                    if (!CopyKeys)
                    {
                        colFirst += 1;
                    }
                    for (int ThisColumn = colFirst; ThisColumn <= colLast; ThisColumn++)
                    {
                        currentCol.AddByIndex(table[ThisRow, ThisColumn]);
                    }
                    Host.Add(table[ThisRow, 0], currentCol);
                }
            }
        }
Exemple #6
0
        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);
        }