merge -r 53370:58178
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildProperty.cs
1 //
2 // BuildProperty.cs: Represents a property
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 // 
7 // (C) 2005 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 #if NET_2_0
29
30 using System;
31 using System.Text;
32 using System.Xml;
33
34 namespace Microsoft.Build.BuildEngine {
35         public class BuildProperty : IBuildProperty {
36         
37                 XmlElement      propertyElement;
38                 XmlAttribute    condition;
39                 string          finalValue;
40                 string          value;
41                 string          name;
42                 PropertyType    propertyType;
43         
44                 public BuildProperty ()
45                         : this (null, null)
46                 {
47                 }
48
49                 public BuildProperty (string propertyName,
50                                 string propertyValue)
51                 {
52                         this.name = propertyName;
53                         this.value = propertyValue;
54                 }
55
56                 public BuildProperty Clone (bool deepClone)
57                 {
58                         BuildProperty bp;
59                         
60                         bp = new BuildProperty ();
61                         bp.condition = this.condition;
62                         bp.finalValue = this.finalValue;
63                         bp.name = this.name;
64                         bp.propertyElement = this.propertyElement;
65                         bp.propertyType = this.propertyType;
66                         bp.value = this.value;
67                         
68                         return bp;
69                 }
70
71                 public static implicit operator string (BuildProperty propertyToCast)
72                 {
73                         if (propertyToCast == null)
74                                 throw new ArgumentNullException ("propertyToCast");
75                         return propertyToCast.ToString ();
76                 }
77
78                 public override string ToString ()
79                 {
80                         if (finalValue != null)
81                                 return finalValue;
82                         else
83                                 return Value;
84                 }
85
86                 
87                 internal void BindToXml (XmlElement propertyElement)
88                 {
89                         if (propertyElement == null)
90                                 throw new ArgumentNullException ("propertyElement");
91                         this.propertyElement = propertyElement;
92                         this.condition = propertyElement.GetAttributeNode ("Condition");
93                         this.name = propertyElement.Name;
94                         this.value = propertyElement.InnerText;
95                 }
96                 
97                 internal void UpdateXml ()
98                 {
99                 }
100                 
101                 public string Condition {
102                         get {
103                                 if (condition == null)
104                                         return null;
105                                 else
106                                         return condition.Value;
107                         }
108                         set {
109                                 if (condition != null)
110                                         condition.Value = value;
111                         }
112                 }
113
114                 public string FinalValue {
115                         get {
116                                 if (finalValue == null) {
117                                         return this.@value;
118                                 } else
119                                         return finalValue;
120                         }
121                         internal set {
122                                 finalValue = value;
123                         }
124                 }
125
126                 public string Name {
127                         get {
128                                 return name;
129                         }
130                 }
131
132                 public string Value {
133                         get {
134                                 return value;
135                         }
136                         set {
137                                 this.@value = value;
138                         }
139                 }
140
141                 internal PropertyType PropertyType {
142                         get { return propertyType; }
143                         set { propertyType = value; }
144                 }
145         }
146
147         internal enum PropertyType {
148                 Reserved,
149                 CommandLine,
150                 Normal,
151                 Environment
152         }
153 }
154
155 #endif