merge -r 60814:60815
[mono.git] / mcs / class / System.XML / System.Xml / XmlNameEntry.cs
1 //
2 // System.Xml.XmlNameEntry.cs
3 //
4 // Authors:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // (C) 2005 Novell, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Collections;
33
34 namespace System.Xml
35 {
36         internal class XmlNameEntry
37         {
38                 public XmlNameEntry (string prefix, string local, string ns)
39                 {
40                         Update (prefix, local, ns);
41                 }
42
43                 public void Update (string prefix, string local, string ns)
44                 {
45                         Prefix = prefix;
46                         LocalName = local;
47                         NS = ns;
48                         Hash = local.GetHashCode () + (prefix.Length > 0 ? prefix.GetHashCode () : 0);
49                 }
50
51                 public string Prefix;
52                 public string LocalName;
53                 public string NS;
54                 public int Hash;
55
56                 string prefixed_name_cache;
57
58                 public override bool Equals (object other)
59                 {
60                         XmlNameEntry e = other as XmlNameEntry;
61                         return e != null && e.Hash == Hash &&
62                                 Object.ReferenceEquals (e.LocalName, LocalName) &&
63                                 Object.ReferenceEquals (e.NS, NS) &&
64                                 Object.ReferenceEquals (e.Prefix, Prefix);
65                 }
66
67                 public override int GetHashCode ()
68                 {
69                         return Hash;
70                 }
71
72                 public string GetPrefixedName (XmlNameEntryCache owner)
73                 {
74                         if (prefixed_name_cache == null)
75                                 prefixed_name_cache =
76                                         owner.GetAtomizedPrefixedName (Prefix, LocalName);
77                         return prefixed_name_cache;
78                 }
79         }
80 }