PDA

View Full Version : Equals fails on proxied object.


avidgoffer
08-10-2007, 07:00 PM
Hello everybody,

I am working with a proxy that tells me if my class has been modified or not and am having trouble with the Equals method. I have a collection that when I call Add does the following:

public IDriver Add()
{
IDriver result = new Driver(this);

ProxyFactoryObject pf = new ProxyFactoryObject();
pf.Target = result;
pf.AddAdvisor(new ModificationAdvisor(result.GetType()));
pf.AddIntroduction(new IsModifiedAdvisor());
pf.ProxyTargetType = false;

return (IDriver)List[List.Add(pf.GetObject())];
}

In the next code when I call Equals it skips the call to Debug.WriteLine.

IDriver driver = Drivers.Add();
if (driver.Equals(driver))
{
Debug.WriteLine("driver = driver")
}

Can anyone help with this?

thanks

Aaron

avidgoffer
08-10-2007, 08:58 PM
We found a work around to the problem with the code below:

public override bool Equals(object obj)
{
object obj1 = obj;
if (obj is IAdvised)
{
obj1 = ((IAdvised)obj).TargetSource.GetTarget();
}
return base.Equals(obj1);
}

thanks

Aaron