Bug 15572. Lookup KnownTypeCollection element types in MSSimpleNamespace
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Construction / ProjectUsingTaskElement.cs
1 //
2 // ProjectUsingTaskElement.cs
3 //
4 // Author:
5 //   Leszek Ciesielski (skolima@gmail.com)
6 //
7 // (C) 2011 Leszek Ciesielski
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
29 using System;
30 using Microsoft.Build.Exceptions;
31
32 namespace Microsoft.Build.Construction
33 {
34         [System.Diagnostics.DebuggerDisplayAttribute ("TaskName={TaskName} AssemblyName={AssemblyName} "
35                                                       + "AssemblyFile={AssemblyFile} Condition={Condition} "
36                                                       + "Runtime={RequiredRuntime} Platform={RequiredPlatform}")]
37         public class ProjectUsingTaskElement : ProjectElementContainer
38         {
39                 internal ProjectUsingTaskElement (string taskName, string assemblyFile, string assemblyName,
40                                                 ProjectRootElement containingProject)
41                 {
42                         TaskName = taskName;
43                         AssemblyFile = assemblyFile;
44                         AssemblyName = assemblyName;
45                         ContainingProject = containingProject;
46                 }
47                 string assemblyFile;
48                 public string AssemblyFile {
49                         get { return assemblyFile ?? String.Empty; }
50                         set { assemblyFile = value; }
51                 }
52                 string assemblyName;
53                 public string AssemblyName {
54                         get { return assemblyName ?? String.Empty; }
55                         set { assemblyName = value; }
56                 }
57                 public UsingTaskParameterGroupElement ParameterGroup {
58                         get { return FirstChild as UsingTaskParameterGroupElement; }
59                 }
60                 public ProjectUsingTaskBodyElement TaskBody {
61                         get { return LastChild as ProjectUsingTaskBodyElement; }
62                 }
63                 string taskFactory;
64                 public string TaskFactory { get { return taskFactory ?? String.Empty; } set { taskFactory = value; } }
65                 string taskName;
66                 public string TaskName { get { return taskName ?? String.Empty; } set { taskName = value; } }
67                 public UsingTaskParameterGroupElement AddParameterGroup ()
68                 {
69                         var @group = ContainingProject.CreateUsingTaskParameterGroupElement ();
70                         PrependChild (@group);
71                         return @group;
72                 }
73                 public ProjectUsingTaskBodyElement AddUsingTaskBody (string evaluate, string taskBody)
74                 {
75                         var body = ContainingProject.CreateUsingTaskBodyElement (evaluate, taskBody);
76                         AppendChild (body);
77                         return body;
78                 }
79                 internal override void LoadAttribute (string name, string value)
80                 {
81                         switch (name) {
82                         case "AssemblyName":
83                                 AssemblyName = value;
84                                 break;
85                         case "AssemblyFile":
86                                 AssemblyFile = value;
87                                 break;
88                         case "TaskFactory":
89                                 TaskFactory = value;
90                                 break;
91                         case "TaskName":
92                                 TaskName = value;
93                                 break;
94                         default:
95                                 base.LoadAttribute (name, value);
96                                 break;
97                         }
98                 }
99                 internal override void SaveValue (System.Xml.XmlWriter writer)
100                 {
101                         SaveAttribute (writer, "AssemblyName", AssemblyName);
102                         SaveAttribute (writer, "AssemblyFile", AssemblyFile);
103                         SaveAttribute (writer, "TaskFactory", TaskFactory);
104                         SaveAttribute (writer, "TaskName", TaskName);
105                         base.SaveValue (writer);
106                 }
107                 internal override string XmlName {
108                         get { return "UsingTask"; }
109                 }
110                 internal override ProjectElement LoadChildElement (string name)
111                 {
112                         switch (name) {
113                         case "ParameterGroup":
114                                 return AddParameterGroup ();
115                         case "Task":
116                                 return AddUsingTaskBody (null, null);
117                         default:
118                                 throw new InvalidProjectFileException (string.Format (
119                                         "Child \"{0}\" is not a known node type.", name));
120                         }
121                 }
122         }
123 }