PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Microsoft.Build/Microsoft.Build/Microsoft/Build/Construction/ProjectParser.cs

#
C# | 540 lines | 501 code | 39 blank | 0 comment | 72 complexity | 8ca0b0456833d1085890dc3d0b08fd98 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.Construction
  2. {
  3. using Microsoft.Build.Evaluation;
  4. using Microsoft.Build.Internal;
  5. using Microsoft.Build.Shared;
  6. using Microsoft.Internal.Performance;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Xml;
  10. internal class ProjectParser
  11. {
  12. private XmlDocumentWithLocation document;
  13. internal const int MaximumChooseNesting = 50;
  14. private ProjectRootElement project;
  15. private bool seenProjectExtensions;
  16. private static readonly string[] validAttributesOnImport = new string[] { "Condition", "Label", "Project" };
  17. private static readonly string[] validAttributesOnItem = new string[] { "Condition", "Label", "Include", "Exclude", "Remove" };
  18. private static readonly string[] validAttributesOnlyConditionAndLabel = new string[] { "Condition", "Label" };
  19. private static readonly string[] validAttributesOnOnError = new string[] { "Condition", "Label", "ExecuteTargets" };
  20. private static readonly string[] validAttributesOnOutput = new string[] { "Condition", "Label", "TaskParameter", "ItemName", "PropertyName" };
  21. private static readonly string[] validAttributesOnTarget = new string[] { "Condition", "Label", "Name", "Inputs", "Outputs", "KeepDuplicateOutputs", "DependsOnTargets", "BeforeTargets", "AfterTargets", "Returns" };
  22. private static readonly string[] validAttributesOnUsingTask = new string[] { "Condition", "Label", "TaskName", "AssemblyFile", "AssemblyName", "TaskFactory", "RequiredPlatform", "RequiredRuntime" };
  23. private static readonly string[] validAttributesOnUsingTaskBody = new string[] { "Evaluate" };
  24. private static readonly string[] validAttributesOnUsingTaskParameter = new string[] { "ParameterType", "Output", "Required" };
  25. private ProjectParser(XmlDocumentWithLocation document, ProjectRootElement project)
  26. {
  27. ErrorUtilities.VerifyThrowInternalNull(project, "project");
  28. ErrorUtilities.VerifyThrowInternalNull(document, "document");
  29. this.document = document;
  30. this.project = project;
  31. }
  32. private void Parse()
  33. {
  34. XmlElementWithLocation element = null;
  35. foreach (XmlNode node in this.document.ChildNodes)
  36. {
  37. if (node.NodeType == XmlNodeType.Element)
  38. {
  39. element = (XmlElementWithLocation) node;
  40. break;
  41. }
  42. }
  43. ProjectErrorUtilities.VerifyThrowInvalidProject(element != null, new ElementLocation(this.document.FullPath), "NoRootProjectElement", "Project");
  44. ProjectErrorUtilities.VerifyThrowInvalidProject(element.Name != "VisualStudioProject", element.Location, "ProjectUpgradeNeeded", this.project.FullPath);
  45. ProjectErrorUtilities.VerifyThrowInvalidProject(element.LocalName == "Project", element.Location, "UnrecognizedElement", element.Name);
  46. if ((element.Prefix.Length > 0) || !string.Equals(element.NamespaceURI, "http://schemas.microsoft.com/developer/msbuild/2003", StringComparison.OrdinalIgnoreCase))
  47. {
  48. ProjectErrorUtilities.ThrowInvalidProject(element.Location, "ProjectMustBeInMSBuildXmlNamespace", "http://schemas.microsoft.com/developer/msbuild/2003");
  49. }
  50. this.ParseProjectElement(element);
  51. }
  52. internal static void Parse(XmlDocumentWithLocation document, ProjectRootElement projectRootElement)
  53. {
  54. using (new Microsoft.Internal.Performance.CodeMarkerStartEnd(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectConstructBegin, Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectConstructEnd))
  55. {
  56. new ProjectParser(document, projectRootElement).Parse();
  57. }
  58. }
  59. private ProjectChooseElement ParseProjectChooseElement(XmlElementWithLocation element, ProjectElementContainer parent, int nestingDepth)
  60. {
  61. ProjectXmlUtilities.VerifyThrowProjectNoAttributes(element);
  62. ProjectChooseElement element2 = new ProjectChooseElement(element, parent, this.project);
  63. nestingDepth++;
  64. ProjectErrorUtilities.VerifyThrowInvalidProject(nestingDepth <= 50, element.Location, "ChooseOverflow", 50);
  65. bool condition = false;
  66. bool flag2 = false;
  67. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  68. {
  69. ProjectElement child = null;
  70. string name = location.Name;
  71. if (name == null)
  72. {
  73. goto Label_00C8;
  74. }
  75. if (!(name == "When"))
  76. {
  77. if (name == "Otherwise")
  78. {
  79. goto Label_00A5;
  80. }
  81. goto Label_00C8;
  82. }
  83. ProjectErrorUtilities.VerifyThrowInvalidProject(!flag2, location.Location, "WhenNotAllowedAfterOtherwise");
  84. child = this.ParseProjectWhenElement(location, element2, nestingDepth);
  85. condition = true;
  86. goto Label_00DF;
  87. Label_00A5:
  88. ProjectErrorUtilities.VerifyThrowInvalidProject(!flag2, location.Location, "MultipleOtherwise");
  89. flag2 = true;
  90. child = this.ParseProjectOtherwiseElement(location, element2, nestingDepth);
  91. goto Label_00DF;
  92. Label_00C8:
  93. ProjectXmlUtilities.ThrowProjectInvalidChildElement(location.Name, element.Name, element.Location);
  94. Label_00DF:
  95. element2.AppendParentedChildNoChecks(child);
  96. }
  97. nestingDepth--;
  98. ProjectErrorUtilities.VerifyThrowInvalidProject(condition, element.Location, "ChooseMustContainWhen");
  99. return element2;
  100. }
  101. private void ParseProjectElement(XmlElementWithLocation element)
  102. {
  103. this.project.SetProjectRootElementFromParser(element, this.project);
  104. this.ParseProjectRootElementChildren(element);
  105. }
  106. private ProjectExtensionsElement ParseProjectExtensionsElement(XmlElementWithLocation element)
  107. {
  108. ProjectXmlUtilities.VerifyThrowProjectNoAttributes(element);
  109. ProjectErrorUtilities.VerifyThrowInvalidProject(!this.seenProjectExtensions, element.Location, "DuplicateProjectExtensions");
  110. this.seenProjectExtensions = true;
  111. return new ProjectExtensionsElement(element, this.project, this.project);
  112. }
  113. private ProjectImportElement ParseProjectImportElement(XmlElementWithLocation element, ProjectElementContainer parent)
  114. {
  115. ProjectErrorUtilities.VerifyThrowInvalidProject((parent is ProjectRootElement) || (parent is ProjectImportGroupElement), element.Location, "UnrecognizedParentElement", parent, element);
  116. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnImport);
  117. ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, "Project");
  118. ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element);
  119. return new ProjectImportElement(element, parent, this.project);
  120. }
  121. private ProjectImportGroupElement ParseProjectImportGroupElement(XmlElementWithLocation element, ProjectRootElement parent)
  122. {
  123. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  124. ProjectImportGroupElement element2 = new ProjectImportGroupElement(element, parent, this.project);
  125. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  126. {
  127. ProjectErrorUtilities.VerifyThrowInvalidProject(location.Name == "Import", location.Location, "UnrecognizedChildElement", location.Name, element.Name);
  128. ProjectImportElement child = this.ParseProjectImportElement(location, element2);
  129. element2.AppendParentedChildNoChecks(child);
  130. }
  131. return element2;
  132. }
  133. private ProjectItemDefinitionGroupElement ParseProjectItemDefinitionGroupElement(XmlElementWithLocation element)
  134. {
  135. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  136. ProjectItemDefinitionGroupElement parent = new ProjectItemDefinitionGroupElement(element, this.project, this.project);
  137. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  138. {
  139. ProjectItemDefinitionElement child = this.ParseProjectItemDefinitionXml(location, parent);
  140. parent.AppendParentedChildNoChecks(child);
  141. }
  142. return parent;
  143. }
  144. private ProjectItemDefinitionElement ParseProjectItemDefinitionXml(XmlElementWithLocation element, ProjectItemDefinitionGroupElement parent)
  145. {
  146. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  147. ProjectItemDefinitionElement element2 = new ProjectItemDefinitionElement(element, parent, this.project);
  148. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  149. {
  150. ProjectMetadataElement child = this.ParseProjectMetadataElement(location, element2);
  151. element2.AppendParentedChildNoChecks(child);
  152. }
  153. return element2;
  154. }
  155. private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
  156. {
  157. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnItem);
  158. bool flag = parent.Parent is ProjectTargetElement;
  159. string name = element.Name;
  160. string attribute = element.GetAttribute("Include");
  161. string str3 = element.GetAttribute("Exclude");
  162. ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute((element.GetAttribute("Remove").Length == 0) || (flag && (attribute.Length == 0)), (XmlAttributeWithLocation) element.Attributes["Remove"]);
  163. ProjectErrorUtilities.VerifyThrowInvalidProject((attribute.Length > 0) || flag, element.Location, "MissingRequiredAttribute", "Include", name);
  164. ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute((str3.Length == 0) || (attribute.Length > 0), (XmlAttributeWithLocation) element.Attributes["Exclude"]);
  165. ProjectErrorUtilities.VerifyThrowInvalidProject((attribute.Length > 0) || (element.Attributes["Include"] == null), element.Location, "MissingRequiredAttribute", "Include", name);
  166. XmlUtilities.VerifyThrowProjectValidElementName(element);
  167. ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[name] == null, element.Location, "CannotModifyReservedItem", name);
  168. ProjectItemElement element2 = new ProjectItemElement(element, parent, this.project);
  169. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  170. {
  171. ProjectMetadataElement child = this.ParseProjectMetadataElement(location, element2);
  172. element2.AppendParentedChildNoChecks(child);
  173. }
  174. return element2;
  175. }
  176. private ProjectItemGroupElement ParseProjectItemGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
  177. {
  178. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  179. ProjectItemGroupElement element2 = new ProjectItemGroupElement(element, parent, this.project);
  180. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  181. {
  182. ProjectItemElement child = this.ParseProjectItemElement(location, element2);
  183. element2.AppendParentedChildNoChecks(child);
  184. }
  185. return element2;
  186. }
  187. private ProjectMetadataElement ParseProjectMetadataElement(XmlElementWithLocation element, ProjectElementContainer parent)
  188. {
  189. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  190. XmlUtilities.VerifyThrowProjectValidElementName(element);
  191. ProjectErrorUtilities.VerifyThrowInvalidProject(!(parent is ProjectItemElement) || (((ProjectItemElement) parent).Remove.Length == 0), element.Location, "ChildElementsBelowRemoveNotAllowed");
  192. ProjectErrorUtilities.VerifyThrowInvalidProject(!FileUtilities.ItemSpecModifiers.IsItemSpecModifier(element.Name), element.Location, "ItemSpecModifierCannotBeCustomMetadata", element.Name);
  193. ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[element.Name] == null, element.Location, "CannotModifyReservedItemMetadata", element.Name);
  194. ProjectMetadataElement element2 = new ProjectMetadataElement(element, parent, this.project);
  195. if (parent is ProjectItemDefinitionElement)
  196. {
  197. ProjectErrorUtilities.VerifyThrowInvalidProject(!Expander<ProjectProperty, ProjectItem>.ExpressionContainsItemVector(element2.Value), element.Location, "MetadataDefinitionCannotContainItemVectorExpression", element2.Value, element2.Name);
  198. }
  199. return element2;
  200. }
  201. private ProjectOnErrorElement ParseProjectOnErrorElement(XmlElementWithLocation element, ProjectTargetElement parent)
  202. {
  203. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnOnError);
  204. ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, "ExecuteTargets");
  205. ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element);
  206. return new ProjectOnErrorElement(element, parent, this.project);
  207. }
  208. private ProjectOtherwiseElement ParseProjectOtherwiseElement(XmlElementWithLocation element, ProjectChooseElement parent, int nestingDepth)
  209. {
  210. ProjectXmlUtilities.VerifyThrowProjectNoAttributes(element);
  211. ProjectOtherwiseElement element2 = new ProjectOtherwiseElement(element, parent, this.project);
  212. this.ParseWhenOtherwiseChildren(element, element2, nestingDepth);
  213. return element2;
  214. }
  215. private ProjectOutputElement ParseProjectOutputElement(XmlElementWithLocation element, ProjectTaskElement parent)
  216. {
  217. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnOutput);
  218. ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, "TaskParameter");
  219. ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element);
  220. element.GetAttribute("TaskParameter");
  221. string attribute = element.GetAttribute("ItemName");
  222. string str2 = element.GetAttribute("PropertyName");
  223. ProjectErrorUtilities.VerifyThrowInvalidProject(((attribute.Length > 0) || (str2.Length > 0)) && ((attribute.Length == 0) || (str2.Length == 0)), element.Location, "InvalidTaskOutputSpecification", parent.Name);
  224. ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, "ItemName");
  225. ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, "PropertyName");
  226. ProjectErrorUtilities.VerifyThrowInvalidProject(!ReservedPropertyNames.IsReservedProperty(str2), element.Location, "CannotModifyReservedProperty", str2);
  227. return new ProjectOutputElement(element, parent, this.project);
  228. }
  229. private ProjectPropertyElement ParseProjectPropertyElement(XmlElementWithLocation element, ProjectPropertyGroupElement parent)
  230. {
  231. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  232. XmlUtilities.VerifyThrowProjectValidElementName(element);
  233. ProjectErrorUtilities.VerifyThrowInvalidProject((XMakeElements.IllegalItemPropertyNames[element.Name] == null) && !ReservedPropertyNames.IsReservedProperty(element.Name), element.Location, "CannotModifyReservedProperty", element.Name);
  234. return new ProjectPropertyElement(element, parent, this.project);
  235. }
  236. private ProjectPropertyGroupElement ParseProjectPropertyGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
  237. {
  238. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnlyConditionAndLabel);
  239. ProjectPropertyGroupElement element2 = new ProjectPropertyGroupElement(element, parent, this.project);
  240. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  241. {
  242. ProjectPropertyElement child = this.ParseProjectPropertyElement(location, element2);
  243. element2.AppendParentedChildNoChecks(child);
  244. }
  245. return element2;
  246. }
  247. private void ParseProjectRootElementChildren(XmlElementWithLocation element)
  248. {
  249. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  250. {
  251. ProjectElement child = null;
  252. switch (location.Name)
  253. {
  254. case "PropertyGroup":
  255. child = this.ParseProjectPropertyGroupElement(location, this.project);
  256. break;
  257. case "ItemGroup":
  258. child = this.ParseProjectItemGroupElement(location, this.project);
  259. break;
  260. case "ImportGroup":
  261. child = this.ParseProjectImportGroupElement(location, this.project);
  262. break;
  263. case "Import":
  264. child = this.ParseProjectImportElement(location, this.project);
  265. break;
  266. case "UsingTask":
  267. child = this.ParseProjectUsingTaskElement(location);
  268. break;
  269. case "Target":
  270. child = this.ParseProjectTargetElement(location);
  271. break;
  272. case "ItemDefinitionGroup":
  273. child = this.ParseProjectItemDefinitionGroupElement(location);
  274. break;
  275. case "Choose":
  276. child = this.ParseProjectChooseElement(location, this.project, 0);
  277. break;
  278. case "ProjectExtensions":
  279. child = this.ParseProjectExtensionsElement(location);
  280. break;
  281. case "Error":
  282. case "Warning":
  283. case "Message":
  284. ProjectErrorUtilities.ThrowInvalidProject(location.Location, "ErrorWarningMessageNotSupported", location.Name);
  285. break;
  286. default:
  287. ProjectXmlUtilities.ThrowProjectInvalidChildElement(location.Name, location.ParentNode.Name, location.Location);
  288. break;
  289. }
  290. this.project.AppendParentedChildNoChecks(child);
  291. }
  292. }
  293. private ProjectTargetElement ParseProjectTargetElement(XmlElementWithLocation element)
  294. {
  295. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnTarget);
  296. ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, "Name");
  297. string str = EscapingUtilities.UnescapeAll(ProjectXmlUtilities.GetAttributeValue(element, "Name"));
  298. int num = str.IndexOfAny(XMakeElements.illegalTargetNameCharacters);
  299. if (num >= 0)
  300. {
  301. ProjectErrorUtilities.ThrowInvalidProject(element.GetAttributeLocation("Name"), "NameInvalid", str, str[num]);
  302. }
  303. ProjectTargetElement parent = new ProjectTargetElement(element, this.project, this.project);
  304. ProjectOnErrorElement element3 = null;
  305. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  306. {
  307. ProjectElement child = null;
  308. string name = location.Name;
  309. if (name == null)
  310. {
  311. goto Label_0168;
  312. }
  313. if (!(name == "PropertyGroup"))
  314. {
  315. if (name == "ItemGroup")
  316. {
  317. goto Label_010E;
  318. }
  319. if (name == "OnError")
  320. {
  321. goto Label_013F;
  322. }
  323. if (name == "ItemDefinitionGroup")
  324. {
  325. goto Label_014E;
  326. }
  327. goto Label_0168;
  328. }
  329. if (element3 != null)
  330. {
  331. ProjectErrorUtilities.ThrowInvalidProject(element3.Location, "NodeMustBeLastUnderElement", "OnError", "Target", location.Name);
  332. }
  333. child = this.ParseProjectPropertyGroupElement(location, parent);
  334. goto Label_0197;
  335. Label_010E:
  336. if (element3 != null)
  337. {
  338. ProjectErrorUtilities.ThrowInvalidProject(element3.Location, "NodeMustBeLastUnderElement", "OnError", "Target", location.Name);
  339. }
  340. child = this.ParseProjectItemGroupElement(location, parent);
  341. goto Label_0197;
  342. Label_013F:
  343. element3 = this.ParseProjectOnErrorElement(location, parent);
  344. child = element3;
  345. goto Label_0197;
  346. Label_014E:
  347. ProjectErrorUtilities.ThrowInvalidProject(location.Location, "ItemDefinitionGroupNotLegalInsideTarget", location.Name);
  348. goto Label_0197;
  349. Label_0168:
  350. if (element3 != null)
  351. {
  352. ProjectErrorUtilities.ThrowInvalidProject(element3.Location, "NodeMustBeLastUnderElement", "OnError", "Target", location.Name);
  353. }
  354. child = this.ParseProjectTaskElement(location, parent);
  355. Label_0197:
  356. parent.AppendParentedChildNoChecks(child);
  357. }
  358. return parent;
  359. }
  360. private ProjectTaskElement ParseProjectTaskElement(XmlElementWithLocation element, ProjectTargetElement parent)
  361. {
  362. foreach (XmlAttributeWithLocation location in element.Attributes)
  363. {
  364. ProjectErrorUtilities.VerifyThrowInvalidProject(!XMakeAttributes.IsBadlyCasedSpecialTaskAttribute(location.Name), location.Location, "BadlyCasedSpecialTaskAttribute", location.Name, element.Name, element.Name);
  365. }
  366. ProjectTaskElement element2 = new ProjectTaskElement(element, parent, this.project);
  367. foreach (XmlElementWithLocation location2 in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  368. {
  369. ProjectErrorUtilities.VerifyThrowInvalidProject(location2.Name == "Output", location2.Location, "UnrecognizedChildElement", location2.Name, element2.Name);
  370. ProjectOutputElement child = this.ParseProjectOutputElement(location2, element2);
  371. element2.AppendParentedChildNoChecks(child);
  372. }
  373. return element2;
  374. }
  375. private ProjectUsingTaskElement ParseProjectUsingTaskElement(XmlElementWithLocation element)
  376. {
  377. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnUsingTask);
  378. ProjectErrorUtilities.VerifyThrowInvalidProject(element.GetAttribute("TaskName").Length > 0, element.Location, "ProjectTaskNameEmpty");
  379. string attribute = element.GetAttribute("AssemblyName");
  380. string str2 = element.GetAttribute("AssemblyFile");
  381. ProjectErrorUtilities.VerifyThrowInvalidProject((attribute.Length > 0) ^ (str2.Length > 0), element.Location, "UsingTaskAssemblySpecification", "UsingTask", "AssemblyName", "AssemblyFile");
  382. ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, "AssemblyName");
  383. ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, "AssemblyFile");
  384. ProjectUsingTaskElement parent = new ProjectUsingTaskElement(element, this.project, this.project);
  385. bool flag = false;
  386. bool flag2 = false;
  387. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  388. {
  389. ProjectElement child = null;
  390. string name = location.Name;
  391. if (name == null)
  392. {
  393. goto Label_0126;
  394. }
  395. if (!(name == "ParameterGroup"))
  396. {
  397. if (name == "Task")
  398. {
  399. goto Label_010D;
  400. }
  401. goto Label_0126;
  402. }
  403. if (flag2)
  404. {
  405. ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(location);
  406. }
  407. child = this.ParseUsingTaskParameterGroupElement(location, parent);
  408. flag2 = true;
  409. goto Label_013E;
  410. Label_010D:
  411. if (flag)
  412. {
  413. ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(location);
  414. }
  415. child = this.ParseUsingTaskBodyElement(location, parent);
  416. flag = true;
  417. goto Label_013E;
  418. Label_0126:
  419. ProjectXmlUtilities.ThrowProjectInvalidChildElement(location.Name, element.Name, element.Location);
  420. Label_013E:
  421. parent.AppendParentedChildNoChecks(child);
  422. }
  423. return parent;
  424. }
  425. private ProjectWhenElement ParseProjectWhenElement(XmlElementWithLocation element, ProjectChooseElement parent, int nestingDepth)
  426. {
  427. ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, "Condition");
  428. ProjectWhenElement element2 = new ProjectWhenElement(element, parent, this.project);
  429. this.ParseWhenOtherwiseChildren(element, element2, nestingDepth);
  430. return element2;
  431. }
  432. private ProjectUsingTaskBodyElement ParseUsingTaskBodyElement(XmlElementWithLocation element, ProjectUsingTaskElement parent)
  433. {
  434. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnUsingTaskBody);
  435. XmlUtilities.VerifyThrowProjectValidElementName(element);
  436. return new ProjectUsingTaskBodyElement(element, parent, this.project);
  437. }
  438. private ProjectUsingTaskParameterElement ParseUsingTaskParameterElement(XmlElementWithLocation element, UsingTaskParameterGroupElement parent)
  439. {
  440. ProjectXmlUtilities.VerifyThrowProjectAttributes(element, validAttributesOnUsingTaskParameter);
  441. XmlUtilities.VerifyThrowProjectValidElementName(element);
  442. return new ProjectUsingTaskParameterElement(element, parent, this.project);
  443. }
  444. private UsingTaskParameterGroupElement ParseUsingTaskParameterGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
  445. {
  446. ProjectXmlUtilities.VerifyThrowProjectNoAttributes(element);
  447. UsingTaskParameterGroupElement element2 = new UsingTaskParameterGroupElement(element, parent, this.project);
  448. HashSet<string> set = new HashSet<string>();
  449. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  450. {
  451. if (set.Contains(location.Name))
  452. {
  453. ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(location);
  454. }
  455. else
  456. {
  457. ProjectUsingTaskParameterElement child = this.ParseUsingTaskParameterElement(location, element2);
  458. element2.AppendParentedChildNoChecks(child);
  459. set.Add(location.Name);
  460. }
  461. }
  462. return element2;
  463. }
  464. private void ParseWhenOtherwiseChildren(XmlElementWithLocation element, ProjectElementContainer parent, int nestingDepth)
  465. {
  466. foreach (XmlElementWithLocation location in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
  467. {
  468. ProjectElement child = null;
  469. string name = location.Name;
  470. if (name == null)
  471. {
  472. goto Label_006D;
  473. }
  474. if (!(name == "PropertyGroup"))
  475. {
  476. if (name == "ItemGroup")
  477. {
  478. goto Label_0056;
  479. }
  480. if (name == "Choose")
  481. {
  482. goto Label_0061;
  483. }
  484. goto Label_006D;
  485. }
  486. child = this.ParseProjectPropertyGroupElement(location, parent);
  487. goto Label_0084;
  488. Label_0056:
  489. child = this.ParseProjectItemGroupElement(location, parent);
  490. goto Label_0084;
  491. Label_0061:
  492. child = this.ParseProjectChooseElement(location, parent, nestingDepth);
  493. goto Label_0084;
  494. Label_006D:
  495. ProjectXmlUtilities.ThrowProjectInvalidChildElement(location.Name, element.Name, element.Location);
  496. Label_0084:
  497. parent.AppendParentedChildNoChecks(child);
  498. }
  499. }
  500. }
  501. }