コード例 #1
0
ファイル: Result.cs プロジェクト: Waz2010/JsonToJsonCompare3
        private void FindMatchedElements()
        {
            var matchedElements = _current.JsonContent.Descendants().OfType <JProperty>()
                                  .Where(x => _previous.JsonContent.Descendants().OfType <JProperty>()
                                         .Any(y => y.Name == x.Name && x.Value.ToString() == y.Value.ToString())).ToList();

            var misMatchedElements = _current.JsonContent.Descendants().OfType <JProperty>()
                                     .Where(x => !_previous.JsonContent.Descendants().OfType <JProperty>()
                                            .Any(y => y.Name == x.Name && x.Value.ToString() == y.Value.ToString())).ToList();

            foreach (var item in matchedElements)
            {
                var result = new FileContentCompareResult
                {
                    JsonElementPath = item.Path,
                    CurrentValue    = item.Value?.ToString(),
                    PreviousValue   = _previous.JsonContent.Descendants().OfType <JProperty>().FirstOrDefault(x => x.Name == item.Name)?.Value.ToString() ?? ""
                };
                _matchedElementsList.Add(result);
            }

            foreach (var item in misMatchedElements)
            {
                var result = new FileContentCompareResult
                {
                    JsonElementPath = item.Path,
                    CurrentValue    = item.Value?.ToString(),
                    PreviousValue   = _previous.JsonContent.Descendants().OfType <JProperty>().FirstOrDefault(x => x.Name == item.Name)?.Value.ToString() ?? ""
                };
                _mismatchedElementsList.Add(result);
            }
        }
コード例 #2
0
ファイル: Result.cs プロジェクト: Waz2010/JsonToJsonCompare3
        private void FindRemovedElements()
        {
            var removed = _current.JsonContent.Descendants().OfType <JProperty>().Where(x => !_previous.JsonContent.Descendants().OfType <JProperty>().Any(g => x.Name == g.Name));
            var added   = _previous.JsonContent.Descendants().OfType <JProperty>().Where(x => !_current.JsonContent.Descendants().OfType <JProperty>().Any(g => x.Name == g.Name));

            foreach (var item in removed)
            {
                var result = new FileContentCompareResult
                {
                    JsonElementPath = item.Path,
                    PreviousValue   = item.Value.ToString(),
                    CurrentValue    = ""
                };

                _removedElementsInNewList.Add(result);
            }

            foreach (var item in added)
            {
                var result = new FileContentCompareResult
                {
                    JsonElementPath = item.Path,
                    PreviousValue   = "",
                    CurrentValue    = item.Value.ToString()
                };

                _addedElementsInNewList.Add(result);
            }
        }