FieldData.IsDirty - possible bug prevents access to private _isDirty flag

FieldData.IsDirty - possible bug prevents access to private _isDirty flag

Old forum URL: forums.lhotka.net/forums/t/10590.aspx


ejames posted on Thursday, August 04, 2011

The FieldData class has the ability to track the Dirty status of its property. In most cases this tracking works as expected.

Here's where it goes wrong for me:

 

 

 

Here's the code...

 

[Serializable()]
public class FieldData : IFieldData
{
    private string _name;
    private T _data;
    private bool _isDirty;
    ...SNIP...

    public virtual T Value
    {
      get
      {
        return _data;
      }
      set
      {
        _data = value;
        _isDirty = true;
      }
    }

    ...SNIP...
    
    public virtual bool IsSelfDirty
    {
      get { return IsDirty; }
    }
    
    public virtual bool IsDirty
    {
      get
      {
        ITrackStatus child = _data as ITrackStatus;
        if (child != null)
        {
          return child.IsDirty;
        }
        else
        {
          return _isDirty;
        }
      }
    }    
}

 

I'd like to call IsSelfDirty but that delegates to IsDirty therefore serving no special purpose.

My suggestion...

Change FieldData.IsSelfDirty to return _isDirty field.

Does this break the semantics of IsSelfDirty?

 

RockfordLhotka replied on Thursday, August 04, 2011

If the field is a reference to a child object, then the child object must manage its own metastate. The parent (the FieldData object) can't manage the metastate of its child - it must delegate through to the child.

ejames replied on Friday, August 05, 2011

Thanks for the reply, Rocky.

My scenario is a little off the beaten track.

I shall mark my child object as Dirty to get the result I require.

 

 

 

Copyright (c) Marimer LLC