Linked Questions
42 questions linked to/from Comparing object properties in c#
5
votes
3
answers
4k
views
How do I compare the fields/properties between POCOs? [duplicate]
Possible Duplicate:
Comparing object properties in c#
Let's say I have a POCO:
public class Person
{
public string Name { get; set; }
public DateTime DateOfBirth { get; set; }
public ...
5
votes
4
answers
2k
views
Clean way to check if all properties, except for two, matches between two objects? [duplicate]
I have a database containing components with about 20 properties. To find out if an update is needed I want to check if all properties for the two objects, except DateCreated and Id, matches.
If all ...
0
votes
1
answer
117
views
compare generic T to new T() always false [duplicate]
I have a generic function(object, object), one of parameters can be new()
when I try to compare object to new() it is always false.
public static void TestFunction<T>(object requestData, ...
203
votes
13
answers
123k
views
How To Test if Type is Primitive
I have a block of code that serializes a type into a Html tag.
Type t = typeof(T); // I pass <T> in as a paramter, where myObj is of type T
tagBuilder.Attributes.Add("class", t.Name);
foreach (...
47
votes
15
answers
4k
views
How to simplify repeating if-then-assign construction?
I have the following method:
protected override bool ModifyExistingEntity(Product entity, ProductModel item)
{
bool isModified = false;
if (entity.Title != item.Title)
{
...
49
votes
10
answers
37k
views
What is "Best Practice" For Comparing Two Instances of a Reference Type?
I came across this recently, up until now I have been happily overriding the equality operator (==) and/or Equals method in order to see if two references types actually contained the same data (i.e. ...
59
votes
8
answers
33k
views
Finding property differences between two C# objects
The project I'm working on needs some simple audit logging for when a user changes their email, billing address, etc. The objects we're working with are coming from different sources, one a WCF ...
31
votes
7
answers
11k
views
How to quickly check if two data transfer objects have equal properties in C#?
I have these data transfer objects:
public class Report
{
public int Id { get; set; }
public int ProjectId { get; set; }
//and so on for many, many properties.
}
I don't want to write
...
14
votes
6
answers
31k
views
Comparing Object properties using reflection
I have two classes Address and Employee as follows:
public class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set;...
13
votes
10
answers
15k
views
Compare two objects using serialization C#
Why it is not a good practice to compare two objects by serializing them and then compare the strings like in the following example?
public class Obj
{
public int Prop1 { get; set; }
public ...
16
votes
5
answers
16k
views
Find differences between two entities of the same type
I'm working on an mvc3 web app. When the user updates something, I want to compare the old data to the new one the user is inputing and for each field that is different add those to a log to create an ...
12
votes
2
answers
8k
views
Comparing 2 objects and retrieve a list of fields with different values
Given a class with 35 fields and 2 objects with a certain number of different fields value.
Is there an clever way to get a list<String> with the fields name where the object are as following?
e....
15
votes
5
answers
8k
views
What is the algorithm used by the memberwise equality test in .NET structs?
What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm.
I am trying to write a recursive ...
8
votes
5
answers
17k
views
Comparing objects
I have a class it contains some string members, some double members and some array objects.
I create two objects of this class, is there any simplest, efficient way of comparing these objects and ...
5
votes
4
answers
4k
views
Comparing two objects' properties simply in c#
I have a class with lots of properties. A shallow copy is enough to fully replicate the object.
I need to compare an object just to check if it contains exactly the same values as another.
My ideas:
...