Re: Accessor Issue

Tech-Archive recommends: Fix windows errors by optimizing your registry



>> The first is to change the IsDirty property of Facility to check
each
>> of its aggregate components, like this:

>> public bool IsDirty
>> {
>> get
>> {
>> return this.dirty || this.address.IsDirty || this...IsDirty
||
>> ...;
>> }
>> }

> well, i cant to that, because the facility is derived from a base
> class, and the base class carry all those isDirty, isNew... flags and

> some other important things..

> see my code before... ( ..base.MarkDirty(); )

Yes, you still can. You should do it like this:

public class BaseClass
{
private bool _isDirty = false;

...
public void MakeDirty()
{
this._isDirty = true;
}

public virtual bool IsDirty
{
get { return this._isDirty; }
}
}

public class Facility : BaseClass
{
private Address _facilityAddress;
...
public override bool IsDirty
{
get { return base.IsDirty || this._facilityAddress.IsDirty ||
.... ; }
}
}

You should have an IsDirty property anyway... nobody should be looking
at the local isDirty flag in the base class. That should be private.
So, all you do is declare the property virtual and then override it in
classes that have complex fields like Addresses and PhoneNumbers.

I think that this is much cleaner and easier than messing with events,
etc.

.