SvgAttributeAttribute.cs 2.89 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
5
6
7
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Svg
{
8
9
10
11
    /// <summary>
    /// Specifies the SVG attribute name of the associated property.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
davescriven's avatar
davescriven committed
12
13
14
15
16
17
    public class SvgAttributeAttribute : System.Attribute
    {
        private const string SVG_NAMESPACE = "http://www.w3.org/2000/svg";
        private string _name;
        private string _namespace;

18
19
20
21
22
23
24
        /// <summary>
        /// When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
        /// </summary>
        /// <param name="obj">An <see cref="T:System.Object"/> to compare with this instance of <see cref="T:System.Attribute"/>.</param>
        /// <returns>
        /// true if this instance equals <paramref name="obj"/>; otherwise, false.
        /// </returns>
davescriven's avatar
davescriven committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        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;
        }

39
40
41
        /// <summary>
        /// Gets the name of the SVG attribute.
        /// </summary>
davescriven's avatar
davescriven committed
42
43
44
45
46
        public string Name
        {
            get { return this._name; }
        }

47
48
49
        /// <summary>
        /// Gets the namespace of the SVG attribute.
        /// </summary>
davescriven's avatar
davescriven committed
50
51
52
53
54
        public string NameSpace
        {
            get { return this._namespace; }
        }

55
56
57
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class.
        /// </summary>
davescriven's avatar
davescriven committed
58
59
60
61
62
        internal SvgAttributeAttribute()
        {
            this._name = String.Empty;
        }

63
64
65
66
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class with the specified attribute name.
        /// </summary>
        /// <param name="name">The name of the SVG attribute.</param>
davescriven's avatar
davescriven committed
67
68
69
70
71
72
        internal SvgAttributeAttribute(string name)
        {
            this._name = name;
            this._namespace = SVG_NAMESPACE;
        }

73
74
75
76
77
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class with the specified SVG attribute name and namespace.
        /// </summary>
        /// <param name="name">The name of the SVG attribute.</param>
        /// <param name="nameSpace">The namespace of the SVG attribute (e.g. http://www.w3.org/2000/svg).</param>
davescriven's avatar
davescriven committed
78
79
80
81
82
83
84
        public SvgAttributeAttribute(string name, string nameSpace)
        {
            this._name = name;
            this._namespace = nameSpace;
        }
    }
}