* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Xml.XLinq / System.Xml.XLinq / XAttribute.cs
1 #if NET_2_0
2
3 using System;
4 using System.Collections;
5 using System.Collections.Generic;
6 using System.IO;
7 using System.Text;
8 using System.Xml;
9
10 using XPI = System.Xml.XLinq.XProcessingInstruction;
11
12
13 namespace System.Xml.XLinq
14 {
15         public class XAttribute
16         {
17                 static IEnumerable <XAttribute> emptySequence =
18                         new List <XAttribute> ();
19
20                 public static IEnumerable <XAttribute> EmptySequence {
21                         get { return emptySequence; }
22                 }
23
24                 XName name;
25                 object value;
26                 XElement parent;
27
28                 public XAttribute (XAttribute source)
29                 {
30                         name = source.name;
31                         value = source.value;
32                 }
33
34                 public XAttribute (XName name, object value)
35                 {
36                         this.name = name;
37                         this.value = XUtil.ToString (value);
38                 }
39
40                 public XName Name {
41                         get { return name; }
42                 }
43
44                 public XElement Parent {
45                         get { return parent; }
46                         internal set {
47                                 parent = value;
48                                 value.InternalAppendAttribute (this);
49                         }
50                 }
51
52                 public string Value {
53                         get { return XUtil.ToString (value); }
54                         set { this.value = value; }
55                 }
56
57                 public override bool Equals (object obj)
58                 {
59                         XAttribute a = obj as XAttribute;
60                         if (a == null)
61                                 return false;
62                         return a.Name == name && a.value == value;
63                 }
64
65                 public override int GetHashCode ()
66                 {
67                         return name.GetHashCode () ^ value.GetHashCode ();
68                 }
69
70                 public static explicit operator bool (XAttribute a)
71                 {
72                         return XUtil.ToBoolean (a.value);
73                 }
74
75                 public static explicit operator Nullable <bool> (XAttribute a)
76                 {
77                         return a.value == null || String.Empty == a.value as string ?
78                                 null : XUtil.ToNullableBoolean (a.value);
79                 }
80
81                 // FIXME: similar conversion methods follow.
82
83                 public void Remove ()
84                 {
85                         if (parent != null) {
86                                 parent.InternalRemoveAttribute (this);
87                                 parent = null;
88                         }
89                 }
90         }
91 }
92
93 #endif