using System;
using System.Diagnostics;
namespace MadMilkman.Ini
{
///
/// Represents a base class for INI content items, and .
///
///
/// All INI items share the same content like , and .
/// These properties are defined on an class, a base class for INI content items.
///
[DebuggerDisplay("Name = {Name}")]
public abstract class IniItem
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string name;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly IniFile parentFile;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private IniComment leadingComment;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private IniComment trailingComment;
///
/// Gets and sets the name of the current .
///
///
/// When setting the value is verified by the item's rule.
///
public string Name
{
get { return this.name; }
set
{
if (this.ParentCollectionCore == null || ((IItemNameVerifier)this.ParentCollectionCore).VerifyItemName(value))
this.name = value;
}
}
///
/// Gets or sets the amount of whitespace characters before this item's name.
///
public int LeftIndentation { get; set; }
///
/// Gets the object that represents a comment that follows this on the same line.
///
public IniComment LeadingComment
{
get
{
if (this.leadingComment == null)
this.leadingComment = new IniComment(IniCommentType.Leading);
return this.leadingComment;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal bool HasLeadingComment { get { return this.leadingComment != null; } }
///
/// Gets the object that represents a comments that occur before this .
///
public IniComment TrailingComment
{
get
{
if (this.trailingComment == null)
this.trailingComment = new IniComment(IniCommentType.Trailing);
return this.trailingComment;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal bool HasTrailingComment { get { return this.trailingComment != null; } }
///
/// Gets the to which this belongs to.
///
public IniFile ParentFile { get { return this.parentFile; } }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal object ParentCollectionCore { get; set; }
internal IniItem(IniFile parentFile, string name, IniComment trailingComment = null)
{
if (name == null)
throw new ArgumentNullException("name");
if (parentFile == null)
throw new ArgumentNullException("parentFile");
this.name = name;
this.parentFile = parentFile;
this.trailingComment = trailingComment;
}
// Deep copy constructor.
internal IniItem(IniFile parentFile, IniItem sourceItem)
{
if (parentFile == null)
throw new ArgumentNullException("parentFile");
this.name = sourceItem.name;
this.parentFile = parentFile;
if (sourceItem.HasLeadingComment)
this.leadingComment = new IniComment(sourceItem.leadingComment);
if (sourceItem.HasTrailingComment)
this.trailingComment = new IniComment(sourceItem.trailingComment);
}
}
}