With code like the following
public class Task
{
string Name;
public static bool operator ==(Task t1, Task t2)
{ return t1.Name = t2.Name && t1.GetType() == t2.GetType(); }
}
public class TaskA : Task
{
int aThing;
public static bool operator ==(TaskA t1, TaskA t2)
{
return (Task)t1 == (Task)t2 && t1.GetType() == t2.GetType()
&& t1.aThing == t2.aThing; }
}
public class TaskB : Task //more of the same
class Stuffin
{
List<Task> Tasks;
void CheckIt()
{
bool theSame = Tasks[0] == Tasks[1];
}
I'm trying to make sure that the derived operator (TaskA.==) is called.
I get compilation error when trying the technique here.
I think i'd be able to get it to work correctly if the operator was not static, because i could then override the base classes operator. Is that possible?
Once i get that how would i compare the base properties (i would think the cast to task type [(Task)t1 == (Task)t2] would not work)?