using System;
namespace SharpVectors.Dom.Css
{
///
/// Creates a static section for a CssXmlDocument.
/// Typical use:
/// using(StaticSection.Use(doc))
/// {
/// // blah blah
/// }
///
public sealed class StaticSection : IDisposable
{
///
/// Previous Static state
///
private bool _previousStatic;
///
/// Document to be handled
///
private CssXmlDocument _cssXmlDocument;
///
/// Initializes a new instance of the class.
///
/// The CSS XML document.
private StaticSection(CssXmlDocument cssXmlDocument)
{
_cssXmlDocument = cssXmlDocument;
_previousStatic = cssXmlDocument.Static;
cssXmlDocument.Static = true;
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
_cssXmlDocument.Static = _previousStatic;
}
///
/// Uses the specified CSS XML document with Static state to true.
///
/// The CSS XML document.
public static IDisposable Use(CssXmlDocument cssXmlDocument)
{
return new StaticSection(cssXmlDocument);
}
}
}