コード例 #1
0
        public CompareBasic CompareBasic(JValue originalValue, JValue newValue)
        {
            CompareBasic compareBasic = new CompareBasic();

            if (originalValue == null && newValue != null)
            {
                compareBasic.Type = ChangeType.Add;
            }
            else if (originalValue != null && newValue == null)
            {
                compareBasic.Type = ChangeType.Delete;
            }
            else
            {
                if (IsEqual(originalValue, newValue))
                {
                    compareBasic.Type = ChangeType.None;
                }
                else
                {
                    compareBasic.Type = ChangeType.Update;
                }
            }

            if (originalValue != null && originalValue.Value != null)
            {
                compareBasic.OriginalValue = originalValue.Value.ToString();
            }
            else
            {
                compareBasic.OriginalValue = string.Empty;
            }

            if (newValue != null && newValue.Value != null)
            {
                compareBasic.NewValue = newValue.Value.ToString();
            }
            else
            {
                compareBasic.NewValue = string.Empty;
            }

            return(compareBasic);
        }
コード例 #2
0
ファイル: CompareHandler.cs プロジェクト: daizhen/JsonCompare
        public CompareBasic CompareBasic(JValue originalValue, JValue newValue)
        {
            CompareBasic compareBasic = new CompareBasic();

            if (originalValue == null && newValue != null)
            {
                compareBasic.Type = ChangeType.Add;
            }
            else if (originalValue != null && newValue == null)
            {
                compareBasic.Type = ChangeType.Delete;
            }
            else
            {
                if (IsEqual(originalValue, newValue))
                {
                    compareBasic.Type = ChangeType.None;
                }
                else
                {
                    compareBasic.Type = ChangeType.Update;
                }
            }

            if (originalValue !=null && originalValue.Value != null)
            {
                compareBasic.OriginalValue = originalValue.Value.ToString();
            }
            else
            {
                compareBasic.OriginalValue = string.Empty;
            }

            if (newValue != null && newValue.Value != null)
            {
                compareBasic.NewValue = newValue.Value.ToString();
            }
            else
            {
                compareBasic.NewValue = string.Empty;
            }

            return compareBasic;
        }