Welcome to mirror list, hosted at ThFree Co, Russian Federation.

QilName.cs « QIL « Xsl « Xml « System « System.Data.SqlXml « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7387507ce8f94888aeabb968c8c4946fd223d753 (plain)
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
//------------------------------------------------------------------------------
// <copyright file="QilName.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics;

namespace System.Xml.Xsl.Qil {

    /// <summary>
    /// View over a Qil name literal.
    /// </summary>
    /// <remarks>
    /// Don't construct QIL nodes directly; instead, use the <see cref="QilFactory">QilFactory</see>.
    /// </remarks>
    internal class QilName : QilLiteral {
        private string local;
        private string uri;
        private string prefix;


        //-----------------------------------------------
        // Constructor
        //-----------------------------------------------

        /// <summary>
        /// Construct a new node
        /// </summary>
        public QilName(QilNodeType nodeType, string local, string uri, string prefix) : base(nodeType, null) {
            LocalName = local;
            NamespaceUri = uri;
            Prefix = prefix;
            Value = this;
        }


        //-----------------------------------------------
        // QilName methods
        //-----------------------------------------------

        public string LocalName {
            get { return this.local; }
            set { this.local = value; }
        }

        public string NamespaceUri {
            get { return this.uri; }
            set { this.uri = value; }
        }

        public string Prefix {
            get { return this.prefix; }
            set { this.prefix = value; }
        }

        /// <summary>
        /// Build the qualified name in the form prefix:local
        /// </summary>
        public string QualifiedName {
            get {
                if (this.prefix.Length == 0) {
                    return this.local;
                }
                else {
                    return this.prefix + ':' + this.local;
                }
            }
        }

        /// <summary>
        /// Override GetHashCode() so that the QilName can be used as a key in the hashtable.
        /// </summary>
        /// <remarks>Does not compare their prefixes (if any).</remarks>
        public override int GetHashCode() {
            return this.local.GetHashCode();
        }

        /// <summary>
        /// Override Equals() so that the QilName can be used as a key in the hashtable.
        /// </summary>
        /// <remarks>Does not compare their prefixes (if any).</remarks>
        public override bool Equals(object other) {
            QilName name = other as QilName;
            if (name == null)
                return false;

            return this.local == name.local && this.uri == name.uri;
        }

        /// <summary>
        /// Implement operator == to prevent exidental referential comarison 
        /// </summary>
        /// <remarks>Does not compare their prefixes (if any).</remarks>
        public static bool operator ==(QilName a, QilName b) {
            if ((object)a == (object)b) {
                return true;
            }
            if ((object)a == null || (object)b == null) {
                return false;
            }
            return a.local == b.local && a.uri == b.uri;
        }

        /// <summary>
        /// Implement operator != to prevent exidental referential comarison 
        /// </summary>
        /// <remarks>Does not compare their prefixes (if any).</remarks>
        public static bool operator !=(QilName a, QilName b) {
            return !(a == b);
        }

        /// <summary>
        /// Return the QilName in this format: "{namespace}prefix:local-name".
        /// If the namespace is empty, return the QilName in this truncated format: "local-name".
        /// If the prefix is empty, return the QilName in this truncated format: "{namespace}local-name".
        /// </summary>
        public override string ToString() {
            if (prefix.Length == 0) {
                if (uri.Length == 0)
                    return local;

                return string.Concat("{", uri, "}", local);
            }

            return string.Concat("{", uri, "}", prefix, ":", local);
        }
    }
}