|
using System;
using System.Configuration;
namespace DateSiteNavigation
{
#region Navigation Section
/// <summary>
/// Class representing a config section in the web.config.
/// </summary>
public class NavigationSection : ConfigurationSection
{
private static NavigationSection _current;
/// <summary>
/// Gets a static reference to the navigation section object in the web.config.
/// </summary>
public static NavigationSection Current
{
get
{
if (_current == null)
{
_current = ConfigurationManager.GetSection("Navigation") as NavigationSection;
}
return _current;
}
}
/// <summary>
/// Gets or sets the navigation elements collection.
/// </summary>
[ConfigurationProperty("elements")]
public NavigationElementCollection Elements
{
get { return base["elements"] as NavigationElementCollection; }
set { base["elements"] = value; }
}
/// <summary>
/// Gets or sets the error elements collection.
/// </summary>
[ConfigurationProperty("errors")]
public ErrorElementCollection Errors
{
get { return base["errors"] as ErrorElementCollection; }
set { base["errors"] = value; }
}
}
#endregion
#region Navigation Elements
/// <summary>
/// Class representing a collection of navigation elements.
/// </summary>
[ConfigurationCollection(typeof(NavigationElement), AddItemName = "element", CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
public class NavigationElementCollection : ConfigurationElementCollection
{
protected override System.Configuration.ConfigurationElement CreateNewElement()
{
return new NavigationElement();
}
protected override object GetElementKey(System.Configuration.ConfigurationElement element)
{
return (element as NavigationElement).StateName;
}
public NavigationElement this[int index]
{
get { return (NavigationElement)base.BaseGet(index); }
}
public NavigationElement this[string stateName]
{
get { return (NavigationElement)base.BaseGet(stateName); }
}
public NavigationElement GetElementByPageName(string pageName)
{
System.Collections.IEnumerator enumerator = this.GetEnumerator();
while (enumerator.MoveNext())
{
NavigationElement current = enumerator.Current as NavigationElement;
if (current.PageName.Equals(pageName))
{
return current;
}
}
return new NavigationElement();
}
}
/// <summary>
/// Class representing a navigation element.
/// </summary>
public class NavigationElement : ConfigurationElement
{
[ConfigurationProperty("stateName")]
public string StateName
{
get { return Convert.ToString(base["stateName"]); }
set { base["stateName"] = value; }
}
[ConfigurationProperty("pageName")]
public string PageName
{
get { return Convert.ToString(base["pageName"]); }
set { base["pageName"] = value; }
}
[ConfigurationProperty("weight")]
public int Weight
{
get { return Convert.ToInt32(base["weight"]); }
set { base["weight"] = value; }
}
}
#endregion
#region Error Elements
/// <summary>
/// Class representing a collection of error elements.
/// </summary>
[ConfigurationCollection(typeof(ErrorElement), AddItemName = "error", CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
public class ErrorElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new ErrorElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return (element as ErrorElement).ErrorName;
}
public ErrorElement this[int index]
{
get { return (ErrorElement)base.BaseGet(index); }
}
public ErrorElement this[string stateName]
{
get { return (ErrorElement)base.BaseGet(stateName); }
}
}
/// <summary>
/// Class representing an error element.
/// </summary>
public class ErrorElement : ConfigurationElement
{
[ConfigurationProperty("errorName")]
public string ErrorName
{
get { return Convert.ToString(base["errorName"]); }
set { base["errorName"] = value; }
}
[ConfigurationProperty("pageName")]
public string PageName
{
get { return Convert.ToString(base["pageName"]); }
set { base["pageName"] = value; }
}
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.