Share via


IVsaItem.IsDirty Property

Returns a value indicating whether the current in-memory representation of the item differs from the persisted representation.

public: __property bool get_IsDirty();
public bool IsDirty {get;}
Public Property Get IsDirty() As Boolean

Return Value

Returns true if the item is dirty, and thus requires saving; returns false if the item is not dirty.

Remarks

The dirty condition occurs either the first time an item is created, or when it is loaded and has been modified.

This property can be used to optimize an implementation of the IVsaEngine.SaveSourceState method, as only dirty items need to be persisted. That is, source state need not be saved until it is detected that the item is dirty. This strategy is illustrated in the example below.

The following table shows the exception that the IsDirty property can throw.

Exception Type

Condition

EngineClosed

The IVsaEngine.Close method has been called and the engine is closed.

Example

The following example shows how an implementation optimizes the IVsaEngine.SaveSourceState method by using the IsDirty property. It simply iterates over all the items in the IVsaItems collection, saving only those that are dirty.

function IVsaEngine.SaveSourceState(IVsaPersistSite Site)
{
   // Only save the code items.
   var item : IVsaCodeItem;

   foreach (item in this.Items)
   {
      // Only save the item if it is dirty.
      if (item.IsDirty)
      {
         Site.SaveElement(item.Name, item.SourceText);
      }
   }
}

See Also

Reference

IVsaItem Interface

IVsaEngine.SaveSourceState Method