473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Compare objects

I have 2 objects that have the same complex structure and I would like
to know if a member has change and which one(s).

For example:

[Serializable]
public struct Person
{
public long m_nID;
public string m_strPrenom;
public string m_strNom;
}

If I have p1 and p2 which are Person, I would like a method like
p1.theMethod(p2) that returns an array of objects with the member(s)
and the value(s) where the values are different.

My structure is big, so I don't know if any method already exists in
dotnet?

Thanks,
Francois
Nov 16 '05 #1
2 2213
Hi Frank,

I propose You to write additional structure e.g.

public struct PersonDetailDifference {
public int IdDifference;

public int PrenomDifference;

public int NomDifference;

// and continue...
}

Results of each fields should correspond with
IComparable.Compare(...) results of two Person
field values.

Person should have a constant structure so i
propose to use another strucure as a result
of comparison.

The good practise is to use the properties
instead of fieds for public access.

Regards

Marcin
I have 2 objects that have the same complex structure and I would like
to know if a member has change and which one(s).

For example:

[Serializable]
public struct Person
{
public long m_nID;
public string m_strPrenom;
public string m_strNom;
}

If I have p1 and p2 which are Person, I would like a method like
p1.theMethod(p2) that returns an array of objects with the member(s)
and the value(s) where the values are different.

My structure is big, so I don't know if any method already exists in
dotnet?

Thanks,
Francois

Nov 16 '05 #2
There is no "out-ouf-the-box" solution for this (to the best of my
knowledge).
But you can automate this task using reflection: Get the metadata of your
type, loop over it's fields/properties and compare each of them, put the
different ones in an array.

Look at Object.GetType; Type.GetFields/GetProperties, FieldInfo.GetValue,
PropertyInfo.GetValue.

Niki

"Frank" <fr*************@bluemail.ch> wrote in
news:39**************************@posting.google.c om...
I have 2 objects that have the same complex structure and I would like
to know if a member has change and which one(s).

For example:

[Serializable]
public struct Person
{
public long m_nID;
public string m_strPrenom;
public string m_strNom;
}

If I have p1 and p2 which are Person, I would like a method like
p1.theMethod(p2) that returns an array of objects with the member(s)
and the value(s) where the values are different.

My structure is big, so I don't know if any method already exists in
dotnet?

Thanks,
Francois

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Helmut Jarausch | last post by:
Hi, what does Python do if two objects aren't comparable (to my opinion) If I've understood "Python in a Nutschell" correctly it should raise an exception but it doesn't do for me. Here are...
4
by: Nicolas Fleury | last post by:
Hi everyone, Is there a way to compare recursively two objects (compare their members recursively)? I'm only interested in equality or non-equality (no need for lower-than...). Thx and...
3
by: Stephen | last post by:
I have to write a .Net application which can compare SQL Databases including things like: - DB structure, PK's, FK's, indexes and types of indexes i.e. should be able to detect if the same index...
8
by: laniik | last post by:
Hi. I have a problem using STL's built in sort that seems impossible to get around. if i have: -------------------------------- struct object { int val; }
3
by: vertigo | last post by:
Hello I have std::map object and i want to have randomly sorted objects in it. I tried to: std::map<int,RandomCompare> myobject; and: struct RandomCompare{ bool operator(int i1, int i2){
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
7
by: Prabhudhas Peter | last post by:
I have two object instances of a same class... and i assigned values in both object instances (or the values can be taken from databse and assigned to the members of the objects)... Now i want to...
4
by: Lamis | last post by:
Hi, what is the best way to compare 2 haschtables contatining objects. the objects has 2 property, name & value. I need to print out the differences -- LZ
50
by: titan nyquist | last post by:
I wish to compare two structs via == but it does not compile. I can overload and create my own == but am I missing something that c# already has implemented? ~titan
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.