fearfulsc2
New member
- Joined
- Dec 10, 2018
- Messages
- 2
- Programming Experience
- 5-10
Hi everyone, I am working on a project for work and the technical design given to me wants me to be able to compare 2 different objects that have the same properties.
Okay, not so bad but then it gets more complex.
There is a third object that has its own set of properties and I need to compare the first two objects from this third object. I'll code a few example classes and explain in further detail.
This is a more basic example of what I am actually working with but I hope it will make my question clearer. Let's say the DifferencesFields class gets this set of data from the database
The goal is to Compare HighSchoolStudent and MiddleSchoolStudent by each of their properties to check for any mismatches/differences between the two objects based off the Fields data and whether we actually want to compare that data or not. The last row in the table shared shows that we want to ignore that comparison for Address while we want to check for all the others.
The HighSchoolStudent and MiddleSchoolStudent can both be different sizes or the same size.
I want to be able see which ones match and which ones are different. There's a more complex requirement wanting me to see if the Ssn(in this example at least) is equal to the other. For example, High School Student has Ssn 123456789
and Middle School Student has Ssn 123-45-6789. At first comparison, they are not equal to each other so they do not match, but we want to then do a second comparison to see if they match if we remove special characters. In this case, they would match. I would then give them a match rating of under 100% since it wasn't a perfect match from the start.
Does anyone have any suggestions on how to go about this and how I can best tackle this?
I was trying to do LINQ and use reflection but I am still running into problems.
Thank you!
Okay, not so bad but then it gets more complex.
There is a third object that has its own set of properties and I need to compare the first two objects from this third object. I'll code a few example classes and explain in further detail.
C#:
public class HighSchoolStudent
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Ssn {get; set; }
public HighSchoolStudentAddress Address { get; set; }
}
public class MiddleSchoolStudent
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Ssn {get; set; }
public MiddleSchoolStudentAddress Address { get; set; }
}
public class DifferenceFields
{
public string GroupCode { get; set; }
public string FieldCode { get; set; }
public string FieldName { get; set; }
public bool Compare { get; set; }
}
public class DifferenceGroups
{
public string GroupCode { get; set; }
public string GroupName { get; set; }
}
This is a more basic example of what I am actually working with but I hope it will make my question clearer. Let's say the DifferencesFields class gets this set of data from the database
Student | FirstName | First Name | 1 |
Student | LastName | Last Name | 1 |
Student | Ssn | Social Security Number | 1 |
Student | Address | Student Address | 0 |
The goal is to Compare HighSchoolStudent and MiddleSchoolStudent by each of their properties to check for any mismatches/differences between the two objects based off the Fields data and whether we actually want to compare that data or not. The last row in the table shared shows that we want to ignore that comparison for Address while we want to check for all the others.
The HighSchoolStudent and MiddleSchoolStudent can both be different sizes or the same size.
I want to be able see which ones match and which ones are different. There's a more complex requirement wanting me to see if the Ssn(in this example at least) is equal to the other. For example, High School Student has Ssn 123456789
and Middle School Student has Ssn 123-45-6789. At first comparison, they are not equal to each other so they do not match, but we want to then do a second comparison to see if they match if we remove special characters. In this case, they would match. I would then give them a match rating of under 100% since it wasn't a perfect match from the start.
Does anyone have any suggestions on how to go about this and how I can best tackle this?
I was trying to do LINQ and use reflection but I am still running into problems.
Thank you!