2 // ProjectUsingTaskElement.cs
5 // Leszek Ciesielski (skolima@gmail.com)
7 // (C) 2011 Leszek Ciesielski
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using Microsoft.Build.Exceptions;
32 namespace Microsoft.Build.Construction
34 [System.Diagnostics.DebuggerDisplayAttribute ("TaskName={TaskName} AssemblyName={AssemblyName} "
35 + "AssemblyFile={AssemblyFile} Condition={Condition} "
36 + "Runtime={RequiredRuntime} Platform={RequiredPlatform}")]
37 public class ProjectUsingTaskElement : ProjectElementContainer
39 internal ProjectUsingTaskElement (string taskName, string assemblyFile, string assemblyName,
40 ProjectRootElement containingProject)
43 AssemblyFile = assemblyFile;
44 AssemblyName = assemblyName;
45 ContainingProject = containingProject;
48 public string AssemblyFile {
49 get { return assemblyFile ?? String.Empty; }
50 set { assemblyFile = value; }
53 public string AssemblyName {
54 get { return assemblyName ?? String.Empty; }
55 set { assemblyName = value; }
57 public UsingTaskParameterGroupElement ParameterGroup {
58 get { return FirstChild as UsingTaskParameterGroupElement; }
60 public ProjectUsingTaskBodyElement TaskBody {
61 get { return LastChild as ProjectUsingTaskBodyElement; }
64 public string TaskFactory { get { return taskFactory ?? String.Empty; } set { taskFactory = value; } }
66 public string TaskName { get { return taskName ?? String.Empty; } set { taskName = value; } }
67 public UsingTaskParameterGroupElement AddParameterGroup ()
69 var @group = ContainingProject.CreateUsingTaskParameterGroupElement ();
70 PrependChild (@group);
73 public ProjectUsingTaskBodyElement AddUsingTaskBody (string evaluate, string taskBody)
75 var body = ContainingProject.CreateUsingTaskBodyElement (evaluate, taskBody);
79 internal override void LoadAttribute (string name, string value)
95 base.LoadAttribute (name, value);
99 internal override void SaveValue (System.Xml.XmlWriter writer)
101 SaveAttribute (writer, "AssemblyName", AssemblyName);
102 SaveAttribute (writer, "AssemblyFile", AssemblyFile);
103 SaveAttribute (writer, "TaskFactory", TaskFactory);
104 SaveAttribute (writer, "TaskName", TaskName);
105 base.SaveValue (writer);
107 internal override string XmlName {
108 get { return "UsingTask"; }
110 internal override ProjectElement LoadChildElement (string name)
113 case "ParameterGroup":
114 return AddParameterGroup ();
116 return AddUsingTaskBody (null, null);
118 throw new InvalidProjectFileException (string.Format (
119 "Child \"{0}\" is not a known node type.", name));