tangxu
2024-12-29 72e75456f8b30ec5b6f355539d9c883b0f810d21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// THIS FILE IS PART OF SVG PROJECT
// THE SVG PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MS-PL License.
// COPYRIGHT (C) svg-net. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/svg-net/SVG
 
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace AntdUI.Svg
{
    /// <summary>
    /// Specifies the SVG attribute name of the associated property.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event)]
    public class SvgAttributeAttribute : System.Attribute
    {
        /// <summary>
        /// Gets a <see cref="string"/> containing the XLink namespace (http://www.w3.org/1999/xlink).
        /// </summary>
        public const string SvgNamespace = "http://www.w3.org/2000/svg";
        public const string XLinkPrefix = "xlink";
        public const string XLinkNamespace = "http://www.w3.org/1999/xlink";
        public const string XmlNamespace = "http://www.w3.org/XML/1998/namespace";
 
        public static readonly List<KeyValuePair<string, string>> Namespaces = new List<KeyValuePair<string, string>>()
                                                                            {
                                                                                new KeyValuePair<string, string>("", SvgNamespace),
                                                                                new KeyValuePair<string, string>(XLinkPrefix, XLinkNamespace),
                                                                                new KeyValuePair<string, string>("xml", XmlNamespace)
                                                                            };
        private bool _inAttrDictionary;
        private string _name;
        private string _namespace;
 
        public override bool Equals(object obj)
        {
            return Match(obj);
        }
 
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
 
        /// <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>
        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, Name) == 0;
        }
 
        /// <summary>
        /// Gets the name of the SVG attribute.
        /// </summary>
        public string NamespaceAndName
        {
            get
            {
                if (_namespace == SvgNamespace)
                    return _name;
                return Namespaces.First(x => x.Value == _namespace).Key + ":" + _name;
            }
        }
 
 
        /// <summary>
        /// Gets the name of the SVG attribute.
        /// </summary>
        public string Name
        {
            get { return _name; }
        }
 
        /// <summary>
        /// Gets the namespace of the SVG attribute.
        /// </summary>
        public string NameSpace
        {
            get { return _namespace; }
        }
 
        public bool InAttributeDictionary
        {
            get { return _inAttrDictionary; }
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgAttributeAttribute"/> class.
        /// </summary>
        internal SvgAttributeAttribute()
        {
            _name = String.Empty;
        }
 
        /// <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>
        internal SvgAttributeAttribute(string name)
        {
            _name = name;
            _namespace = SvgNamespace;
        }
 
        internal SvgAttributeAttribute(string name, bool inAttrDictionary)
        {
            _name = name;
            _namespace = SvgNamespace;
            _inAttrDictionary = inAttrDictionary;
        }
 
        /// <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>
        public SvgAttributeAttribute(string name, string nameSpace)
        {
            _name = name;
            _namespace = nameSpace;
        }
    }
}