using System;
using System.Xml;
using Chernobyl.Collections.Generic.Event;
namespace Chernobyl.Reflection.Template.Xml
{
///
/// A class which can be passed to the last
/// parameter of the
///
/// method. This class will use the value of the XML "id" attribute to name
/// the given to it.
///
public class XmlIdAttributeProcessor
{
///
/// Initializes a new instance of the
/// class.
///
/// The component that is to be given the name
/// of the XML ID attributes value.
public XmlIdAttributeProcessor(IComponent component)
{
Component = component;
}
///
/// Performs an implicit conversion from
/// to
/// .
///
/// The to
/// convert to an .
/// The result of the conversion.
public static implicit operator Action(XmlIdAttributeProcessor processor)
{
return processor.AttributeProcessor;
}
///
/// The name used by XML's id attribute, which is "id".
///
public const string AttributeName = "id";
///
/// The URI used by XML attributes, which is
/// "http://www.w3.org/XML/1998/namespace".
///
public const string AttributeUri = "http://www.w3.org/XML/1998/namespace";
///
/// Passed to the
/// method to grab the value from the "id" attribute so that it can be
/// used as a name on the passed to this class.
///
/// The to process.
void AttributeProcessor(XmlAttribute xmlAttribute)
{
if (xmlAttribute.Name == AttributeName &&
xmlAttribute.Prefix == AttributeUri)
Component.Name = xmlAttribute.Value;
}
///
/// The component that is to be given the name of the XML ID attributes
/// value.
///
IComponent Component { get; set; }
}
}