Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 09:17

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Merging objects

Discussion on Merging objects within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
ssamko's Avatar
 
elite*gold: 1908
Join Date: Jan 2013
Posts: 828
Received Thanks: 629
Merging objects

Hello guys I want to merge 2 objects to 1. Those objects can have properties which can have properties etc(multilevel). An in case the source object has some null properties they wont replace old data.
Why do I need it ? I got some JSON data from game and I put them to object with specified structure.

Struct of my object:
Code:
public partial class JsonObjects
{
        [JsonProperty("data")]
        public Data Data { get; set; }
}

public partial class Data
{
        [JsonProperty("user")]
        public User User { get; set; }

        [JsonProperty("character")]
        public Character Character { get; set; }
}
	
public partial class User
{
        [JsonProperty("id")]
        public long? Id { get; set; }

        [JsonProperty("email")]
        public string Email { get; set; }
}
	
public partial class Character
{
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("game_currency")]
        public long? GameCurrency { get; set; }
}
Main:
Code:
JsonObjects destination = new JsonObjects();
string html;
while(true){
	html= GetFreshData();
	JsonObjects newData = JsonConvert.DeserializeObject<JsonObjects>(html);
	// put NEW data from obj: "newData" to "destination"
}
Do you have an idea how can I effectively merge it ?

Thank you !
ssamko is offline  
Old 11/19/2018, 16:53   #2
 
Hypos''s Avatar
 
elite*gold: 0
Join Date: Nov 2018
Posts: 1
Received Thanks: 0
I don't know if I got you right there but what you're seemingly looking for is a "deep merge" function.

Basically you loop through your new object and see if it has any property that is _not_ already in the source object (on the same level, I suppose?). If the respective source property is a null-reference you just ignore it and continue the loop.

If the property is an object itself, you call the function recursively.

Of course this solution requires a JSON parser, but you can find plenty of those on the net and NuGet.
Hypos' is offline  
Old 11/21/2018, 20:42   #3
 
ssamko's Avatar
 
elite*gold: 1908
Join Date: Jan 2013
Posts: 828
Received Thanks: 629
Quote:
Originally Posted by Hypos' View Post
I don't know if I got you right there but what you're seemingly looking for is a "deep merge" function.

Basically you loop through your new object and see if it has any property that is _not_ already in the source object (on the same level, I suppose?). If the respective source property is a null-reference you just ignore it and continue the loop.

If the property is an object itself, you call the function recursively.

Of course this solution requires a JSON parser, but you can find plenty of those on the net and NuGet.
yes you did understand it well..so called "deep merge" is what I wanted and finally I have found one library for that on Nuget. Thnx !
ssamko is offline  
Reply


Similar Threads Similar Threads
[IDEE/FRAGE]Merging accounts
08/11/2011 - Metin2 - 10 Replies
Hallo Epvp, Meine Frage wäre Account Merging auf Metin2 Server Nützlich ja oder nein Welche Negativen und Positiven Seiten bringt es mit sich *_*
[Question]Merging ?
10/23/2010 - EO PServer Hosting - 8 Replies
Hey guys i wander if is it possible to merge account , legions and pets ect.. from adb to another ?
POLL how does everyone feel about this merging rule?
03/23/2009 - Conquer Online 2 - 10 Replies
BABYICEY/MAYFAIRE and ARBITER merging! There will be NO Character Transfer any more. If you have an account and own characters on both servers, only ONE character will be preserved. Which character will remain is determined by these factors, as listed in order of importance: 1. Has more Conquer Points. 2. Has been reborn. 3. Has higher level. 4. Created Earlier.
MERGING OF Sydney and Toronto is big mistake! Please help sign the petition
12/29/2007 - Eudemons Online - 10 Replies
petition closed, sorry. We have private server files & guide, so we won't suffer from TQ bitching anymore I guess.



All times are GMT +2. The time now is 09:17.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.