Skybound Rebar

RebarTheme.AssertNotReadOnly Method 

Throws an exception if IsReadOnly property is true.

[Visual Basic]
Protected Sub AssertNotReadOnly()
[C#]
protected void AssertNotReadOnly();

Remarks

When making a preset for a custom theme, call this method before each of its property setters to ensure the preset is not read-only.

Example

This example displays the members from a custom theme class called SpecialTheme. It demonstrates how to use IsReadOnly and AssertNotReadOnly (drawing code is omitted for clarity).

/// <summary>
/// Initializes a new instance of a <see cref="SpecialTheme"/>.
/// </summary>
public SpecialTheme()
{
}

/// <summary>Private constructor for presets.</summary>
private SpecialTheme(bool readOnly)
{
    this.IsReadOnly = readOnly;
}

static SpecialTheme()
{
    // create the preset object
    _Blue = new SpecialTheme(true);
    
    // assign the field values directly to avoid the set assessor
    _Blue.BackColor = Color._DarkBlue;
    _Blue.TextColor = Color._LightBlue;
}

/// <summary>
/// Gets the special theme preset which uses blue colors.
/// </summary>
public static SpecialTheme Blue
{
    get { return _Blue; }
}
static SpecialTheme _Blue;

/// <summary>
/// Gets or sets the background color of a rebar.
/// </summary>
/// <value>A <see cref="Color"/> structure representing the background color of a rebar.</value>
public Color BackColor
{
    get { return _BackColor; }
    set { AssertNotReadOnly(); _BackColor = value; }
}
Color _BackColor;

/// <summary>
/// Gets or sets the color of text on a rebar.
/// </summary>
/// <value>A <see cref="Color"/> structure representing the color of text on a rebar.</value>
public Color TextColor
{
    get { return _TextColor; }
    set { AssertNotReadOnly(); _TextColor = value; }
}
Color _TextColor;

See Also

RebarTheme Class | Skybound.Rebar.Rendering Namespace