using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Svg
{
///
/// Specifies the SVG attribute name of the associated property.
///
[AttributeUsage(AttributeTargets.Property)]
public class SvgAttributeAttribute : System.Attribute
{
///
/// Gets a containing the XLink namespace (http://www.w3.org/1999/xlink).
///
public const string SVG_NAMESPACE = "http://www.w3.org/2000/svg";
public const string XLinkPrefix = "xlink";
public const string XLinkNamespace = "http://www.w3.org/1999/xlink";
public static readonly List> Namespaces = new List>()
{
new KeyValuePair("", SVG_NAMESPACE),
new KeyValuePair(XLinkPrefix, XLinkNamespace)
};
private string _name;
private string _namespace;
///
/// When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
///
/// An to compare with this instance of .
///
/// true if this instance equals ; otherwise, false.
///
public override bool Match(object obj)
{
SvgAttributeAttribute indicator = obj as SvgAttributeAttribute;
if (indicator == null)
return false;
// Always match if either value is String.Empty (wildcard)
if (indicator.Name == String.Empty)
return false;
return String.Compare(indicator.Name, this.Name) == 0;
}
///
/// Gets the name of the SVG attribute.
///
public string NamespaceAndName
{
get
{
if (_namespace == SVG_NAMESPACE)
return _name;
return Namespaces.First(x => x.Value == _namespace).Key + ":" + _name;
}
}
///
/// Gets the name of the SVG attribute.
///
public string Name
{
get { return this._name; }
}
///
/// Gets the namespace of the SVG attribute.
///
public string NameSpace
{
get { return this._namespace; }
}
///
/// Initializes a new instance of the class.
///
internal SvgAttributeAttribute()
{
this._name = String.Empty;
}
///
/// Initializes a new instance of the class with the specified attribute name.
///
/// The name of the SVG attribute.
internal SvgAttributeAttribute(string name)
{
this._name = name;
this._namespace = SVG_NAMESPACE;
}
///
/// Initializes a new instance of the class with the specified SVG attribute name and namespace.
///
/// The name of the SVG attribute.
/// The namespace of the SVG attribute (e.g. http://www.w3.org/2000/svg).
public SvgAttributeAttribute(string name, string nameSpace)
{
this._name = name;
this._namespace = nameSpace;
}
}
}