SimpleHelpers.Net | Micro-libraries for .Net | Functional Programming library
kandi X-RAY | SimpleHelpers.Net Summary
kandi X-RAY | SimpleHelpers.Net Summary
Micro-libraries (pieces of utility code) for .Net that are safe and simple to use. In every project there are lot’s of reusable patterns that we find our selves rewriting or just doing some copy & paste, and thus the idea behind SimpleHelpers micro-libraries is to create a small collection of such code but keeping it reliable and easy to use.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SimpleHelpers.Net
SimpleHelpers.Net Key Features
SimpleHelpers.Net Examples and Code Snippets
Community Discussions
Trending Discussions on SimpleHelpers.Net
QUESTION
I'm trying to compare two C# objects by converting them to JSON and then making a diff. It works fine for all primitives but I don't understand why when I change items in a list that had items the comparison is retuning an object instead of an array.
I'm going to list 3 cases, the first 2 go by as expected:
Case 1 - previous list was empty and one item was added later ...ANSWER
Answered 2017-Aug-24 at 12:48That's probably because of the way the code you linked (ObjectDiffPatch
) builds up the array diff object. This is the relevant part, as I recreated it in LINQPad:
I added this as an image because that tooltip is important here. But let's start at the top:
If one of the arrays is empty, it properly keeps the original structure: grabs the two arrays (one of which is empty), and adds them under the field name "Companies".
If, however, neither are empty, then it starts comparing their contents, piece by piece. And when a difference is found, the code adds it to the diff object using AddNewValuesToken
, which expects a field name as its third parameter, but here we don't have a field name, just an array index.
Now, the code "solves" this by converting the array index to string
, and treating it as a field name. No wonder that the resulting JObject will treat it that way too – this is why you see an object in the output, where what used to be array indices, become fields.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SimpleHelpers.Net
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page