I have two Lists of objects with the same elements and values:
parameters = new List<Parameter>() { new Parameter() { parameterName="value", parameterType="string"} }
the Parameter class looks like this:
public class Parameter
{
public string parameterName;
public string parameterType;
}
and I want to compare it with an identical List of objects with the same Elements and Values, via an unit-test.
my Method Class(I created before Method objects, which have stored a List of Parameter objects):
public class Method
{
public List<Parameter> parameters { get; set;}
public string modifier { get; set; }
public string name { get; set; }
public string type { get; set; }
public override bool Equals(object obj)
{
return this.modifier == ((Method)obj).modifier && this.name == ((Method)obj).name && this.type == ((Method)obj).type
&& this.parameters == ((Method)obj).parameters;
}
}
my problem is in the Equals method, at the point of this.parameters == ... :
public override bool Equals(object obj)
{
return this.modifier == ((Method)obj).modifier && this.name == ((Method)obj).name && this.type == ((Method)obj).type
&& this.parameters == ((Method)obj).parameters;
}
By the way, all other criteria in this method are working. Modifier, name and type are returning the right value compared to the object. Because of these are basic string values and the comparison is much easier. It gets more complicated when I want to do the same for the List of objects.
How can I compare two Lists of Parameter-objects in this Equals()-Method, do I need to compare the elements each(like comparing parameterName and parameterType of all objects in the list)?