SvgAttributeAttribute.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ComponentModel;
  6. #pragma warning disable
  7. namespace Svg
  8. {
  9. /// <summary>
  10. /// Specifies the SVG attribute name of the associated property.
  11. /// </summary>
  12. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event)]
  13. public class SvgAttributeAttribute : System.Attribute
  14. {
  15. /// <summary>
  16. /// Gets a <see cref="string"/> containing the XLink namespace (http://www.w3.org/1999/xlink).
  17. /// </summary>
  18. public const string SvgNamespace = "http://www.w3.org/2000/svg";
  19. public const string XLinkPrefix = "xlink";
  20. public const string XLinkNamespace = "http://www.w3.org/1999/xlink";
  21. public const string XmlNamespace = "http://www.w3.org/XML/1998/namespace";
  22. public static readonly List<KeyValuePair<string, string>> Namespaces = new List<KeyValuePair<string, string>>()
  23. {
  24. new KeyValuePair<string, string>("", SvgNamespace),
  25. new KeyValuePair<string, string>(XLinkPrefix, XLinkNamespace),
  26. new KeyValuePair<string, string>("xml", XmlNamespace)
  27. };
  28. private bool _inAttrDictionary;
  29. private string _name;
  30. private string _namespace;
  31. public override bool Equals(object obj)
  32. {
  33. return Match(obj);
  34. }
  35. /// <summary>
  36. /// When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
  37. /// </summary>
  38. /// <param name="obj">An <see cref="T:System.Object"/> to compare with this instance of <see cref="T:System.Attribute"/>.</param>
  39. /// <returns>
  40. /// true if this instance equals <paramref name="obj"/>; otherwise, false.
  41. /// </returns>
  42. public override bool Match(object obj)
  43. {
  44. SvgAttributeAttribute indicator = obj as SvgAttributeAttribute;
  45. if (indicator == null)
  46. return false;
  47. // Always match if either value is String.Empty (wildcard)
  48. if (indicator.Name == String.Empty)
  49. return false;
  50. return String.Compare(indicator.Name, this.Name) == 0;
  51. }
  52. /// <summary>
  53. /// Gets the name of the SVG attribute.
  54. /// </summary>
  55. public string NamespaceAndName
  56. {
  57. get
  58. {
  59. if (_namespace == SvgNamespace)
  60. return _name;
  61. return Namespaces.First(x => x.Value == _namespace).Key + ":" + _name;
  62. }
  63. }
  64. /// <summary>
  65. /// Gets the name of the SVG attribute.
  66. /// </summary>
  67. public string Name
  68. {
  69. get { return this._name; }
  70. }
  71. /// <summary>
  72. /// Gets the namespace of the SVG attribute.
  73. /// </summary>
  74. public string NameSpace
  75. {
  76. get { return this._namespace; }
  77. }
  78. public bool InAttributeDictionary
  79. {
  80. get { return this._inAttrDictionary; }
  81. }
  82. /// <summary>
  83. /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class.
  84. /// </summary>
  85. internal SvgAttributeAttribute()
  86. {
  87. this._name = String.Empty;
  88. }
  89. /// <summary>
  90. /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class with the specified attribute name.
  91. /// </summary>
  92. /// <param name="name">The name of the SVG attribute.</param>
  93. internal SvgAttributeAttribute(string name)
  94. {
  95. this._name = name;
  96. this._namespace = SvgNamespace;
  97. }
  98. internal SvgAttributeAttribute(string name, bool inAttrDictionary)
  99. {
  100. this._name = name;
  101. this._namespace = SvgNamespace;
  102. this._inAttrDictionary = inAttrDictionary;
  103. }
  104. /// <summary>
  105. /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class with the specified SVG attribute name and namespace.
  106. /// </summary>
  107. /// <param name="name">The name of the SVG attribute.</param>
  108. /// <param name="nameSpace">The namespace of the SVG attribute (e.g. http://www.w3.org/2000/svg).</param>
  109. public SvgAttributeAttribute(string name, string nameSpace)
  110. {
  111. this._name = name;
  112. this._namespace = nameSpace;
  113. }
  114. }
  115. }
  116. #pragma warning restore