public CompareArray CompareArray(JArray originalArray, JArray newArray)
        {
            CompareArray resultArray = new CompareArray();

            if (newArray == null && originalArray == null)
            {
                throw new Exception("Both values are null..");
            }

            if (newArray == null && originalArray != null)
            {
                //Original value was deleted.
                foreach (JToken item in originalArray)
                {
                    resultArray.Items.Add(Compare(item, null));
                }
            }
            else if (originalArray == null && newArray != null)
            {
                //New added items.
                foreach (JToken item in newArray)
                {
                    resultArray.Items.Add(Compare(null, item));
                }
            }
            else
            {
                for (int i = 0; i < originalArray.Count; i++)
                {
                    if (i >= newArray.Count)
                    {
                        //Original value was deleted
                        resultArray.Items.Add(Compare(originalArray[i], null));
                    }
                    else
                    {
                        //Original value was updated
                        resultArray.Items.Add(Compare(originalArray[i], newArray[i]));
                    }
                }
                for (int i = originalArray.Count; i < newArray.Count; i++)
                {
                    //Original value was added
                    resultArray.Items.Add(Compare(null, newArray[i]));
                }
            }
            return(resultArray);
        }
Ejemplo n.º 2
0
        public CompareArray CompareArray(JArray originalArray, JArray newArray)
        {
            CompareArray resultArray = new CompareArray();

            if (newArray == null && originalArray == null)
            {
                throw new Exception("Both values are null..");
            }

            if (newArray == null && originalArray != null)
            {
                //Original value was deleted.
                foreach (JToken item in originalArray)
                {
                    resultArray.Items.Add(Compare(item, null));
                }
            }
            else if (originalArray == null && newArray !=null)
            {
                //New added items.
                foreach (JToken item in newArray)
                {
                    resultArray.Items.Add(Compare(null, item));
                }
            }
            else
            {
                for (int i = 0; i < originalArray.Count; i++)
                {
                    if (i >= newArray.Count)
                    {
                        //Original value was deleted
                        resultArray.Items.Add(Compare(originalArray[i], null));
                    }
                    else
                    {
                        //Original value was updated
                        resultArray.Items.Add(Compare(originalArray[i], newArray[i]));
                    }
                }
                for (int i = originalArray.Count; i < newArray.Count; i++)
                {
                    //Original value was added
                    resultArray.Items.Add(Compare(null, newArray[i]));
                }
            }
            return resultArray;
        }