PageRenderTime 80ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Microsoft.Build/Microsoft.Build/Microsoft/Build/Evaluation/Expander!2.cs

#
C# | 3960 lines | 3951 code | 9 blank | 0 comment | 31 complexity | 76d716ef0e206723446b06fb2f45bbf0 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.Evaluation
  2. {
  3. using Microsoft.Build;
  4. using Microsoft.Build.Collections;
  5. using Microsoft.Build.Execution;
  6. using Microsoft.Build.Internal;
  7. using Microsoft.Build.Shared;
  8. using Microsoft.Win32;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Concurrent;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Globalization;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Reflection;
  18. using System.Runtime;
  19. using System.Runtime.CompilerServices;
  20. using System.Runtime.InteropServices;
  21. using System.Text;
  22. using System.Text.RegularExpressions;
  23. using System.Threading;
  24. internal class Expander<P, I> where P: class, IProperty where I: class, IItem
  25. {
  26. private static readonly bool defaultWarnForUninitializedProperties;
  27. private static char[] expandableChars;
  28. private static CompareInfo invariantCompareInfo;
  29. private IItemProvider<I> items;
  30. private IMetadataTable metadata;
  31. private IPropertyProvider<P> properties;
  32. private Microsoft.Build.Evaluation.UsedUninitializedProperties usedUninitializedProperties;
  33. static Expander()
  34. {
  35. Expander<P, I>.defaultWarnForUninitializedProperties = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDWARNONUNINITIALIZEDPROPERTY"));
  36. Expander<P, I>.expandableChars = new char[] { '$', '%', '@' };
  37. Expander<P, I>.invariantCompareInfo = CultureInfo.InvariantCulture.CompareInfo;
  38. }
  39. internal Expander(IPropertyProvider<P> properties)
  40. {
  41. this.properties = properties;
  42. this.usedUninitializedProperties = new Microsoft.Build.Evaluation.UsedUninitializedProperties();
  43. }
  44. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  45. internal Expander(IPropertyProvider<P> properties, IItemProvider<I> items) : this(properties)
  46. {
  47. this.items = items;
  48. }
  49. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  50. internal Expander(IPropertyProvider<P> properties, IItemProvider<I> items, IMetadataTable metadata) : this(properties, items)
  51. {
  52. this.metadata = metadata;
  53. }
  54. private static void AddArgument(List<string> arguments, StringBuilder argumentBuilder)
  55. {
  56. ErrorUtilities.VerifyThrowArgumentNull(argumentBuilder, "argumentBuilder");
  57. string strB = OpportunisticIntern.StringBuilderToString(argumentBuilder).Trim();
  58. if (string.Compare("null", strB, StringComparison.OrdinalIgnoreCase) == 0)
  59. {
  60. arguments.Add(null);
  61. }
  62. else if (strB.Length > 0)
  63. {
  64. if ((strB[0] == '\'') && (strB[strB.Length - 1] == '\''))
  65. {
  66. arguments.Add(strB.Trim(new char[] { '\'' }));
  67. }
  68. else if ((strB[0] == '`') && (strB[strB.Length - 1] == '`'))
  69. {
  70. arguments.Add(strB.Trim(new char[] { '`' }));
  71. }
  72. else if ((strB[0] == '"') && (strB[strB.Length - 1] == '"'))
  73. {
  74. arguments.Add(strB.Trim(new char[] { '"' }));
  75. }
  76. else
  77. {
  78. arguments.Add(strB);
  79. }
  80. }
  81. else
  82. {
  83. arguments.Add(strB);
  84. }
  85. }
  86. internal IList<T> ExpandIntoItemsLeaveEscaped<T>(string expression, IItemFactory<I, T> itemFactory, ExpanderOptions options, IElementLocation elementLocation) where T: class, IItem
  87. {
  88. if (expression.Length == 0)
  89. {
  90. return ReadOnlyEmptyList<T>.Instance;
  91. }
  92. ErrorUtilities.VerifyThrowInternalNull(elementLocation, "elementLocation");
  93. expression = MetadataExpander<P, I>.ExpandMetadataLeaveEscaped(expression, this.metadata, options);
  94. expression = PropertyExpander<P, I, P>.ExpandPropertiesLeaveEscaped(expression, this.properties, options, elementLocation, this.usedUninitializedProperties);
  95. List<T> list = new List<T>();
  96. if (expression.Length != 0)
  97. {
  98. foreach (string str in ExpressionShredder.SplitSemiColonSeparatedList(expression))
  99. {
  100. bool flag;
  101. IList<T> collection = ItemExpander<P, I>.ExpandSingleItemVectorExpressionIntoItems<I, T>((Expander<P, I>) this, str, this.items, itemFactory, options, false, out flag, elementLocation);
  102. if (((collection == null) || (collection.Count > 0)) && ((options & ExpanderOptions.BreakOnNotEmpty) != ExpanderOptions.Invalid))
  103. {
  104. return null;
  105. }
  106. if (collection != null)
  107. {
  108. list.AddRange(collection);
  109. }
  110. else
  111. {
  112. T item = itemFactory.CreateItem(str);
  113. list.Add(item);
  114. }
  115. }
  116. }
  117. return list;
  118. }
  119. internal string ExpandIntoStringAndUnescape(string expression, ExpanderOptions options, IElementLocation elementLocation)
  120. {
  121. string escapedString = this.ExpandIntoStringLeaveEscaped(expression, options, elementLocation);
  122. return ((escapedString == null) ? null : EscapingUtilities.UnescapeAll(escapedString));
  123. }
  124. internal string ExpandIntoStringLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
  125. {
  126. if (expression.Length == 0)
  127. {
  128. return string.Empty;
  129. }
  130. ErrorUtilities.VerifyThrowInternalNull(elementLocation, "elementLocation");
  131. string str = PropertyExpander<P, I, P>.ExpandPropertiesLeaveEscaped(MetadataExpander<P, I>.ExpandMetadataLeaveEscaped(expression, this.metadata, options), this.properties, options, elementLocation, this.usedUninitializedProperties);
  132. return ItemExpander<P, I>.ExpandItemVectorsIntoString<I>((Expander<P, I>) this, str, this.items, options, elementLocation);
  133. }
  134. internal IList<string> ExpandIntoStringListLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
  135. {
  136. ErrorUtilities.VerifyThrow((options & ExpanderOptions.BreakOnNotEmpty) == ExpanderOptions.Invalid, "not supported");
  137. return ExpressionShredder.SplitSemiColonSeparatedList(this.ExpandIntoStringLeaveEscaped(expression, options, elementLocation));
  138. }
  139. internal IList<ProjectItemInstance.TaskItem> ExpandIntoTaskItemsLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
  140. {
  141. return this.ExpandIntoItemsLeaveEscaped<ProjectItemInstance.TaskItem>(expression, (IItemFactory<I, ProjectItemInstance.TaskItem>) ProjectItemInstance.TaskItem.TaskItemFactory.Instance, options, elementLocation);
  142. }
  143. internal object ExpandPropertiesLeaveTypedAndEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
  144. {
  145. if (expression.Length == 0)
  146. {
  147. return string.Empty;
  148. }
  149. ErrorUtilities.VerifyThrowInternalNull(elementLocation, "elementLocation");
  150. return PropertyExpander<P, I, P>.ExpandPropertiesLeaveTypedAndEscaped(MetadataExpander<P, I>.ExpandMetadataLeaveEscaped(expression, this.metadata, options), this.properties, options, elementLocation, this.usedUninitializedProperties);
  151. }
  152. internal IList<T> ExpandSingleItemVectorExpressionIntoItems<T>(string expression, IItemFactory<I, T> itemFactory, ExpanderOptions options, bool includeNullItems, out bool isTransformExpression, IElementLocation elementLocation) where T: class, IItem
  153. {
  154. if (expression.Length == 0)
  155. {
  156. isTransformExpression = false;
  157. return ReadOnlyEmptyList<T>.Instance;
  158. }
  159. ErrorUtilities.VerifyThrowInternalNull(elementLocation, "elementLocation");
  160. return ItemExpander<P, I>.ExpandSingleItemVectorExpressionIntoItems<I, T>((Expander<P, I>) this, expression, this.items, itemFactory, options, includeNullItems, out isTransformExpression, elementLocation);
  161. }
  162. internal static bool ExpressionContainsItemVector(string expression)
  163. {
  164. return (ExpressionShredder.GetReferencedItemExpressions(expression) != null);
  165. }
  166. internal static bool ExpressionMayContainExpandableExpressions(string expression)
  167. {
  168. return (expression.IndexOfAny(Expander<P, I>.expandableChars) > -1);
  169. }
  170. private static unsafe string[] ExtractFunctionArguments(IElementLocation elementLocation, string expressionFunction, string argumentsString)
  171. {
  172. int length = argumentsString.Length;
  173. List<string> arguments = new List<string>();
  174. StringBuilder argumentBuilder = new StringBuilder(length);
  175. fixed (char* str = ((char*) argumentsString))
  176. {
  177. char* chPtr = str;
  178. for (int i = 0; i < length; i++)
  179. {
  180. if (((i < (length - 1)) && (chPtr[i] == '$')) && (chPtr[i + 1] == '('))
  181. {
  182. int startIndex = i;
  183. i += 2;
  184. i = Expander<P, I>.ScanForClosingParenthesis(argumentsString, i);
  185. if (i == -1)
  186. {
  187. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, AssemblyResources.GetString("InvalidFunctionPropertyExpressionDetailMismatchedParenthesis"));
  188. }
  189. argumentBuilder.Append(argumentsString.Substring(startIndex, (i - startIndex) + 1));
  190. }
  191. else if (((chPtr[i] == '`') || (chPtr[i] == '"')) || (chPtr[i] == '\''))
  192. {
  193. int num4 = i;
  194. i++;
  195. i = Expander<P, I>.ScanForClosingQuote(argumentsString[num4], argumentsString, i);
  196. if (i == -1)
  197. {
  198. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, AssemblyResources.GetString("InvalidFunctionPropertyExpressionDetailMismatchedQuote"));
  199. }
  200. argumentBuilder.Append(argumentsString.Substring(num4, (i - num4) + 1));
  201. }
  202. else if (chPtr[i] == ',')
  203. {
  204. Expander<P, I>.AddArgument(arguments, argumentBuilder);
  205. argumentBuilder.Remove(0, argumentBuilder.Length);
  206. }
  207. else
  208. {
  209. argumentBuilder.Append(chPtr[i]);
  210. }
  211. }
  212. }
  213. Expander<P, I>.AddArgument(arguments, argumentBuilder);
  214. return arguments.ToArray();
  215. }
  216. private static bool IsValidPropertyName(string propertyName)
  217. {
  218. if ((propertyName.Length == 0) || !XmlUtilities.IsValidInitialElementNameCharacter(propertyName[0]))
  219. {
  220. return false;
  221. }
  222. for (int i = 1; i < propertyName.Length; i++)
  223. {
  224. if (!XmlUtilities.IsValidSubsequentElementNameCharacter(propertyName[i]))
  225. {
  226. return false;
  227. }
  228. }
  229. return true;
  230. }
  231. private static int ScanForClosingParenthesis(string expression, int index)
  232. {
  233. bool potentialPropertyFunction = false;
  234. bool potentialRegistryFunction = false;
  235. return Expander<P, I>.ScanForClosingParenthesis(expression, index, out potentialPropertyFunction, out potentialRegistryFunction);
  236. }
  237. private static unsafe int ScanForClosingParenthesis(string expression, int index, out bool potentialPropertyFunction, out bool potentialRegistryFunction)
  238. {
  239. int num = 1;
  240. int length = expression.Length;
  241. potentialPropertyFunction = false;
  242. potentialRegistryFunction = false;
  243. fixed (char* str = ((char*) expression))
  244. {
  245. char* chPtr = str;
  246. while ((index < length) && (num > 0))
  247. {
  248. char quoteChar = chPtr[index];
  249. switch (quoteChar)
  250. {
  251. case '\'':
  252. case '`':
  253. case '"':
  254. index++;
  255. index = Expander<P, I>.ScanForClosingQuote(quoteChar, expression, index);
  256. if (index < 0)
  257. {
  258. return -1;
  259. }
  260. break;
  261. case '(':
  262. num++;
  263. break;
  264. case ')':
  265. num--;
  266. break;
  267. case '.':
  268. case '[':
  269. case '$':
  270. potentialPropertyFunction = true;
  271. break;
  272. default:
  273. if (quoteChar == ':')
  274. {
  275. potentialRegistryFunction = true;
  276. }
  277. break;
  278. }
  279. index++;
  280. }
  281. }
  282. index--;
  283. if (num != 0)
  284. {
  285. return -1;
  286. }
  287. return index;
  288. }
  289. private static unsafe int ScanForClosingQuote(char quoteChar, string expression, int index)
  290. {
  291. fixed (char* str = ((char*) expression))
  292. {
  293. char* chPtr = str;
  294. while (index < expression.Length)
  295. {
  296. if (chPtr[index] == quoteChar)
  297. {
  298. return index;
  299. }
  300. index++;
  301. }
  302. }
  303. return -1;
  304. }
  305. internal IMetadataTable Metadata
  306. {
  307. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  308. get
  309. {
  310. return this.metadata;
  311. }
  312. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  313. set
  314. {
  315. this.metadata = value;
  316. }
  317. }
  318. internal Microsoft.Build.Evaluation.UsedUninitializedProperties UsedUninitializedProperties
  319. {
  320. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  321. get
  322. {
  323. return this.usedUninitializedProperties;
  324. }
  325. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  326. set
  327. {
  328. this.usedUninitializedProperties = value;
  329. }
  330. }
  331. internal bool WarnForUninitializedProperties
  332. {
  333. get
  334. {
  335. return this.usedUninitializedProperties.Warn;
  336. }
  337. set
  338. {
  339. this.usedUninitializedProperties.Warn = value;
  340. }
  341. }
  342. private class Function<T> where T: class, IProperty
  343. {
  344. private string[] arguments;
  345. private BindingFlags bindingFlags;
  346. private string expression;
  347. private string expressionRootName;
  348. private string name;
  349. private Type objectType;
  350. private string remainder;
  351. private UsedUninitializedProperties usedUninitializedProperties;
  352. internal Function(Type objectType, string expression, string expressionRootName, string name, string[] arguments, BindingFlags bindingFlags, string remainder, UsedUninitializedProperties usedUninitializedProperties)
  353. {
  354. this.name = name;
  355. if (arguments == null)
  356. {
  357. this.arguments = new string[0];
  358. }
  359. else
  360. {
  361. this.arguments = arguments;
  362. }
  363. this.expressionRootName = expressionRootName;
  364. this.expression = expression;
  365. this.objectType = objectType;
  366. this.bindingFlags = bindingFlags;
  367. this.remainder = remainder;
  368. this.usedUninitializedProperties = usedUninitializedProperties;
  369. }
  370. private static object[] CoerceArguments(object[] args, ParameterInfo[] parameters)
  371. {
  372. object[] objArray = new object[args.Length];
  373. try
  374. {
  375. for (int i = 0; i < parameters.Length; i++)
  376. {
  377. if (args[i] != null)
  378. {
  379. if (parameters[i].ParameterType == typeof(char[]))
  380. {
  381. objArray[i] = args[i].ToString().ToCharArray();
  382. }
  383. else if ((parameters[i].ParameterType.IsEnum && (args[i] is string)) && ((string) args[i]).Contains("."))
  384. {
  385. Type parameterType = parameters[i].ParameterType;
  386. string oldValue = parameterType.Name + ".";
  387. string str2 = parameterType.FullName + ".";
  388. string str3 = args[i].ToString().Replace('|', ',').Replace(str2, "").Replace(oldValue, "");
  389. objArray[i] = Enum.Parse(parameterType, str3);
  390. }
  391. else
  392. {
  393. objArray[i] = Convert.ChangeType(args[i], parameters[i].ParameterType, CultureInfo.InvariantCulture);
  394. }
  395. }
  396. }
  397. }
  398. catch (InvalidCastException)
  399. {
  400. return null;
  401. }
  402. return objArray;
  403. }
  404. private static Expander<P, I>.Function<T> ConstructFunction(IElementLocation elementLocation, string expressionFunction, string expressionRootName, Type objectType, int argumentStartIndex, int methodStartIndex, UsedUninitializedProperties usedUninitializedProperties)
  405. {
  406. string[] strArray;
  407. string str;
  408. string str2 = string.Empty;
  409. BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.IgnoreCase;
  410. if ((argumentStartIndex > -1) && !expressionFunction.Substring(methodStartIndex, argumentStartIndex - methodStartIndex).Contains("."))
  411. {
  412. string str3;
  413. str = expressionFunction.Substring(methodStartIndex, argumentStartIndex - methodStartIndex).Trim();
  414. argumentStartIndex++;
  415. int num = Expander<P, I>.ScanForClosingParenthesis(expressionFunction, argumentStartIndex);
  416. ErrorUtilities.VerifyThrow(num != -1, "Unmatched braces when constructing function.", "$(" + expressionFunction + ")");
  417. bindingFlags |= BindingFlags.InvokeMethod;
  418. if (argumentStartIndex == (expressionFunction.Length - 1))
  419. {
  420. str3 = string.Empty;
  421. strArray = new string[0];
  422. }
  423. else
  424. {
  425. str3 = expressionFunction.Substring(argumentStartIndex, num - argumentStartIndex);
  426. if (string.IsNullOrEmpty(str3))
  427. {
  428. strArray = new string[0];
  429. }
  430. else
  431. {
  432. strArray = Expander<P, I>.ExtractFunctionArguments(elementLocation, expressionFunction, str3);
  433. }
  434. str2 = expressionFunction.Substring(num + 1);
  435. }
  436. }
  437. else
  438. {
  439. int index = expressionFunction.IndexOf('.', methodStartIndex);
  440. int length = expressionFunction.Length - methodStartIndex;
  441. int num4 = expressionFunction.IndexOf('[', methodStartIndex);
  442. if ((num4 >= 0) && (num4 < index))
  443. {
  444. index = num4;
  445. }
  446. strArray = new string[0];
  447. if (index > 0)
  448. {
  449. length = index - methodStartIndex;
  450. str2 = expressionFunction.Substring(index);
  451. }
  452. string str4 = expressionFunction.Substring(methodStartIndex, length).Trim();
  453. ProjectErrorUtilities.VerifyThrowInvalidProject(str4.Length > 0, elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, string.Empty);
  454. bindingFlags |= BindingFlags.GetProperty | BindingFlags.GetField;
  455. str = str4;
  456. }
  457. if ((string.IsNullOrEmpty(str2) || (str2[0] == '.')) || (str2[0] == '['))
  458. {
  459. return new Expander<P, I>.Function<T>(objectType, expressionFunction, expressionRootName, str, strArray, bindingFlags, str2, usedUninitializedProperties);
  460. }
  461. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, string.Empty);
  462. return null;
  463. }
  464. private static Expander<P, I>.Function<T> ConstructIndexerFunction(string expressionFunction, IElementLocation elementLocation, object propertyValue, string propertyName, Type objectType, int methodStartIndex, string argumentsContent, UsedUninitializedProperties usedUnInitializedProperties)
  465. {
  466. string str2;
  467. string[] strArray;
  468. string remainder = expressionFunction.Substring(methodStartIndex);
  469. if (string.IsNullOrEmpty(argumentsContent))
  470. {
  471. strArray = new string[0];
  472. }
  473. else
  474. {
  475. strArray = Expander<P, I>.ExtractFunctionArguments(elementLocation, expressionFunction, argumentsContent);
  476. }
  477. if (propertyValue is Array)
  478. {
  479. str2 = "GetValue";
  480. }
  481. else if (propertyValue is string)
  482. {
  483. str2 = "get_Chars";
  484. }
  485. else
  486. {
  487. str2 = "get_Item";
  488. }
  489. return new Expander<P, I>.Function<T>(objectType, expressionFunction, propertyName, str2, strArray, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.IgnoreCase, remainder, usedUnInitializedProperties);
  490. }
  491. internal object Execute(object objectInstance, IPropertyProvider<T> properties, ExpanderOptions options, IElementLocation elementLocation)
  492. {
  493. object propertyValue = string.Empty;
  494. object[] args = null;
  495. try
  496. {
  497. if (objectInstance == null)
  498. {
  499. if (!this.IsStaticMethodAvailable(this.objectType, this.name))
  500. {
  501. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionMethodUnavailable", this.name, this.objectType.FullName);
  502. }
  503. this.bindingFlags |= BindingFlags.Static;
  504. if (this.objectType == typeof(IntrinsicFunctions))
  505. {
  506. this.bindingFlags |= BindingFlags.NonPublic;
  507. }
  508. }
  509. else
  510. {
  511. this.bindingFlags |= BindingFlags.Instance;
  512. if (objectInstance is string)
  513. {
  514. objectInstance = EscapingUtilities.UnescapeAll((string) objectInstance);
  515. }
  516. }
  517. args = new object[this.arguments.Length];
  518. for (int i = 0; i < this.arguments.Length; i++)
  519. {
  520. object obj3 = Expander<P, I>.PropertyExpander<T>.ExpandPropertiesLeaveTypedAndEscaped(this.arguments[i], properties, options, elementLocation, this.usedUninitializedProperties);
  521. string escapedString = obj3 as string;
  522. if (escapedString != null)
  523. {
  524. args[i] = EscapingUtilities.UnescapeAll(escapedString);
  525. }
  526. else
  527. {
  528. args[i] = obj3;
  529. }
  530. }
  531. if (((objectInstance != null) && (args.Length == 1)) && (string.Equals("Equals", this.name, StringComparison.OrdinalIgnoreCase) || string.Equals("CompareTo", this.name, StringComparison.OrdinalIgnoreCase)))
  532. {
  533. args[0] = Convert.ChangeType(args[0], objectInstance.GetType(), CultureInfo.InvariantCulture);
  534. }
  535. if (string.Equals("new", this.name, StringComparison.OrdinalIgnoreCase))
  536. {
  537. propertyValue = this.LateBindExecute(null, BindingFlags.Public | BindingFlags.Instance, null, args, true);
  538. }
  539. else
  540. {
  541. try
  542. {
  543. propertyValue = this.objectType.InvokeMember(this.name, this.bindingFlags, Type.DefaultBinder, objectInstance, args, CultureInfo.InvariantCulture);
  544. }
  545. catch (MissingMethodException exception)
  546. {
  547. if ((this.bindingFlags & BindingFlags.InvokeMethod) != BindingFlags.InvokeMethod)
  548. {
  549. throw;
  550. }
  551. propertyValue = this.LateBindExecute(exception, this.bindingFlags, objectInstance, args, false);
  552. }
  553. }
  554. if (((propertyValue is string) && !string.Equals("Unescape", this.name, StringComparison.OrdinalIgnoreCase)) && !string.Equals("Escape", this.name, StringComparison.OrdinalIgnoreCase))
  555. {
  556. propertyValue = EscapingUtilities.Escape((string) propertyValue);
  557. }
  558. if (string.IsNullOrEmpty(this.remainder))
  559. {
  560. return propertyValue;
  561. }
  562. return Expander<P, I>.PropertyExpander<T>.ExpandPropertyBody(this.remainder, propertyValue, properties, options, elementLocation, this.usedUninitializedProperties);
  563. }
  564. catch (TargetInvocationException exception2)
  565. {
  566. string str2 = this.GenerateStringOfMethodExecuted(this.expression, objectInstance, this.name, args);
  567. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", str2, exception2.InnerException.Message.Replace("\r\n", " "));
  568. return null;
  569. }
  570. catch (Exception exception3)
  571. {
  572. if (ExceptionHandling.NotExpectedFunctionException(exception3))
  573. {
  574. throw;
  575. }
  576. if (Expander<P, I>.invariantCompareInfo.IndexOf(this.expression, "::", CompareOptions.OrdinalIgnoreCase) > -1)
  577. {
  578. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionStaticMethodSyntax", this.expression, exception3.Message.Replace("Microsoft.Build.Evaluation.IntrinsicFunctions.", "[MSBuild]::"));
  579. }
  580. else
  581. {
  582. string str3 = this.GenerateStringOfMethodExecuted(this.expression, objectInstance, this.name, args);
  583. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", str3, exception3.Message);
  584. }
  585. return null;
  586. }
  587. }
  588. internal static Expander<P, I>.Function<T> ExtractPropertyFunction(string expressionFunction, IElementLocation elementLocation, object propertyValue, UsedUninitializedProperties usedUnInitializedProperties)
  589. {
  590. string propertyName = null;
  591. Type objectType = null;
  592. string str2 = expressionFunction;
  593. int index = expressionFunction.IndexOf('(');
  594. if (index > -1)
  595. {
  596. str2 = expressionFunction.Substring(0, index);
  597. }
  598. ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(str2), elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, string.Empty);
  599. int methodStartIndex = -1;
  600. if ((propertyValue == null) && (str2[0] == '['))
  601. {
  602. int num3 = str2.IndexOf(']', 1);
  603. if (num3 < 1)
  604. {
  605. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionStaticMethodSyntax", expressionFunction, string.Empty);
  606. }
  607. string typeName = str2.Substring(1, num3 - 1);
  608. methodStartIndex = num3 + 1;
  609. objectType = Expander<P, I>.Function<T>.GetTypeForStaticMethod(typeName);
  610. if (objectType == null)
  611. {
  612. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionTypeUnavailable", expressionFunction, typeName);
  613. }
  614. if (((str2.Length > (methodStartIndex + 2)) && (str2[methodStartIndex] == ':')) && (str2[methodStartIndex + 1] == ':'))
  615. {
  616. methodStartIndex += 2;
  617. }
  618. else
  619. {
  620. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionStaticMethodSyntax", expressionFunction, string.Empty);
  621. }
  622. }
  623. else
  624. {
  625. if (expressionFunction[0] == '[')
  626. {
  627. objectType = propertyValue.GetType();
  628. int num4 = expressionFunction.IndexOf(']', 1);
  629. if (num4 < 1)
  630. {
  631. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, AssemblyResources.GetString("InvalidFunctionPropertyExpressionDetailMismatchedSquareBrackets"));
  632. }
  633. string argumentsContent = expressionFunction.Substring(1, num4 - 1);
  634. methodStartIndex = num4 + 1;
  635. return Expander<P, I>.Function<T>.ConstructIndexerFunction(expressionFunction, elementLocation, propertyValue, propertyName, objectType, methodStartIndex, argumentsContent, usedUnInitializedProperties);
  636. }
  637. methodStartIndex = str2.IndexOf('.');
  638. if (methodStartIndex == -1)
  639. {
  640. return null;
  641. }
  642. methodStartIndex++;
  643. }
  644. if (objectType == null)
  645. {
  646. int length = str2.IndexOf('.');
  647. propertyName = str2.Substring(0, length);
  648. if ((propertyValue == null) && !Expander<P, I>.IsValidPropertyName(propertyName))
  649. {
  650. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", expressionFunction, string.Empty);
  651. }
  652. objectType = typeof(string);
  653. }
  654. if (propertyValue != null)
  655. {
  656. objectType = propertyValue.GetType();
  657. }
  658. return Expander<P, I>.Function<T>.ConstructFunction(elementLocation, expressionFunction, propertyName, objectType, index, methodStartIndex, usedUnInitializedProperties);
  659. }
  660. private string GenerateStringOfMethodExecuted(string expression, object objectInstance, string name, object[] args)
  661. {
  662. string str = string.Empty;
  663. if (args != null)
  664. {
  665. foreach (object obj2 in args)
  666. {
  667. if (obj2 == null)
  668. {
  669. str = str + "null";
  670. }
  671. else
  672. {
  673. string str2 = obj2.ToString();
  674. if ((obj2 is string) && (str2.Length == 0))
  675. {
  676. str = str + "''";
  677. }
  678. else
  679. {
  680. str = str + obj2.ToString();
  681. }
  682. }
  683. str = str + ", ";
  684. }
  685. if (str.Length > 2)
  686. {
  687. str = str.Substring(0, str.Length - 2);
  688. }
  689. }
  690. if (objectInstance == null)
  691. {
  692. string fullName = this.objectType.FullName;
  693. if (this.objectType == typeof(IntrinsicFunctions))
  694. {
  695. fullName = "MSBuild";
  696. }
  697. if ((this.bindingFlags & BindingFlags.InvokeMethod) == BindingFlags.InvokeMethod)
  698. {
  699. return ("[" + fullName + "]::" + name + "(" + str + ")");
  700. }
  701. return ("[" + fullName + "]::" + name);
  702. }
  703. string str4 = "\"" + objectInstance + "\"";
  704. if ((this.bindingFlags & BindingFlags.InvokeMethod) == BindingFlags.InvokeMethod)
  705. {
  706. return (str4 + "." + name + "(" + str + ")");
  707. }
  708. return (str4 + "." + name);
  709. }
  710. private static Type GetTypeForStaticMethod(string typeName)
  711. {
  712. Type typeFromAssembly;
  713. Tuple<string, Type> tuple;
  714. if (FunctionConstants.AvailableStaticMethods.TryGetValue(typeName, out tuple) && (tuple != null))
  715. {
  716. ErrorUtilities.VerifyThrow((tuple.Item1 != null) || (tuple.Item2 != null), "Function type information needs either string or type represented.");
  717. if (tuple.Item2 != null)
  718. {
  719. return tuple.Item2;
  720. }
  721. if (tuple.Item1 != null)
  722. {
  723. typeName = tuple.Item1;
  724. typeFromAssembly = Type.GetType(typeName, false, true);
  725. FunctionConstants.AvailableStaticMethods[typeName] = new Tuple<string, Type>(typeName, typeFromAssembly);
  726. return typeFromAssembly;
  727. }
  728. }
  729. typeFromAssembly = Type.GetType(typeName, false, true);
  730. if (typeFromAssembly == null)
  731. {
  732. if (!(Environment.GetEnvironmentVariable("MSBUILDENABLEALLPROPERTYFUNCTIONS") == "1"))
  733. {
  734. return typeFromAssembly;
  735. }
  736. if (typeFromAssembly == null)
  737. {
  738. typeFromAssembly = Expander<P, I>.Function<T>.GetTypeFromAssembly(typeName, "System");
  739. }
  740. if (typeFromAssembly == null)
  741. {
  742. typeFromAssembly = Expander<P, I>.Function<T>.GetTypeFromAssembly(typeName, "System.Core");
  743. }
  744. if (typeFromAssembly == null)
  745. {
  746. typeFromAssembly = Expander<P, I>.Function<T>.GetTypeFromAssemblyUsingNamespace(typeName);
  747. }
  748. if (typeFromAssembly != null)
  749. {
  750. FunctionConstants.AvailableStaticMethods[typeName] = new Tuple<string, Type>(typeName, typeFromAssembly);
  751. }
  752. }
  753. return typeFromAssembly;
  754. }
  755. private static Type GetTypeFromAssembly(string typeName, string candidateAssemblyName)
  756. {
  757. Type type = null;
  758. Assembly assembly = Assembly.LoadWithPartialName(candidateAssemblyName);
  759. if (assembly != null)
  760. {
  761. type = assembly.GetType(typeName, false, true);
  762. }
  763. return type;
  764. }
  765. private static Type GetTypeFromAssemblyUsingNamespace(string typeName)
  766. {
  767. string str = typeName;
  768. int length = str.LastIndexOf('.');
  769. Type typeFromAssembly = null;
  770. ErrorUtilities.VerifyThrow(length > 0, "Invalid typename: {0}", typeName);
  771. while (length > 0)
  772. {
  773. string candidateAssemblyName = null;
  774. candidateAssemblyName = str.Substring(0, length);
  775. typeFromAssembly = Expander<P, I>.Function<T>.GetTypeFromAssembly(typeName, candidateAssemblyName);
  776. if (typeFromAssembly != null)
  777. {
  778. return typeFromAssembly;
  779. }
  780. length = candidateAssemblyName.LastIndexOf('.');
  781. }
  782. return null;
  783. }
  784. private bool IsStaticMethodAvailable(Type objectType, string methodName)
  785. {
  786. if (objectType == typeof(IntrinsicFunctions))
  787. {
  788. return true;
  789. }
  790. string key = objectType.FullName + "::" + methodName;
  791. return (FunctionConstants.AvailableStaticMethods.ContainsKey(objectType.FullName) || (FunctionConstants.AvailableStaticMethods.ContainsKey(key) || (Environment.GetEnvironmentVariable("MSBUILDENABLEALLPROPERTYFUNCTIONS") == "1")));
  792. }
  793. private object LateBindExecute(Exception ex, BindingFlags bindingFlags, object objectInstance, object[] args, bool isConstructor)
  794. {
  795. ParameterInfo[] parameters = null;
  796. MethodBase[] constructors = null;
  797. MethodBase base2 = null;
  798. Type[] types = new Type[this.arguments.Length];
  799. for (int i = 0; i < this.arguments.Length; i++)
  800. {
  801. types[i] = typeof(string);
  802. }
  803. if (isConstructor)
  804. {
  805. base2 = this.objectType.GetConstructor(bindingFlags, null, types, null);
  806. }
  807. else
  808. {
  809. base2 = this.objectType.GetMethod(this.name, bindingFlags, null, types, null);
  810. }
  811. if (base2 == null)
  812. {
  813. if (isConstructor)
  814. {
  815. constructors = this.objectType.GetConstructors(bindingFlags);
  816. }
  817. else
  818. {
  819. constructors = this.objectType.GetMethods(bindingFlags);
  820. }
  821. object[] objArray = null;
  822. foreach (MethodBase base3 in constructors)
  823. {
  824. parameters = base3.GetParameters();
  825. if ((parameters.Length == this.arguments.Length) && (isConstructor || string.Equals(base3.Name, this.name, StringComparison.OrdinalIgnoreCase)))
  826. {
  827. objArray = Expander<P, I>.Function<T>.CoerceArguments(args, parameters);
  828. if (objArray != null)
  829. {
  830. base2 = base3;
  831. args = objArray;
  832. break;
  833. }
  834. }
  835. }
  836. }
  837. object obj2 = null;
  838. if ((base2 != null) && (args != null))
  839. {
  840. if (isConstructor)
  841. {
  842. obj2 = ((ConstructorInfo) base2).Invoke(args);
  843. }
  844. else
  845. {
  846. obj2 = ((MethodInfo) base2).Invoke(objectInstance, args);
  847. }
  848. }
  849. else if (!isConstructor)
  850. {
  851. throw ex;
  852. }
  853. if ((obj2 == null) && isConstructor)
  854. {
  855. throw new TargetInvocationException(new MissingMethodException());
  856. }
  857. return obj2;
  858. }
  859. internal string ExpressionRootName
  860. {
  861. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  862. get
  863. {
  864. return this.expressionRootName;
  865. }
  866. }
  867. }
  868. private static class ItemExpander
  869. {
  870. private static bool ExpandItemVectorMatchIntoStringBuilder<S>(Expander<P, I> expander, ExpressionShredder.ItemExpressionCapture match, IItemProvider<S> items, IElementLocation elementLocation, StringBuilder builder, ExpanderOptions options) where S: class, IItem
  871. {
  872. string itemType = match.ItemType;
  873. string str2 = (match.Separator != null) ? match.Separator : ";";
  874. ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(itemType), elementLocation, "InvalidFunctionPropertyExpression");
  875. ICollection<S> itemsOfType = items.GetItems(itemType);
  876. if (itemsOfType.Count != 0)
  877. {
  878. if (match.Captures == null)
  879. {
  880. foreach (S local in itemsOfType)
  881. {
  882. if ((local.EvaluatedIncludeEscaped.Length > 0) && ((options & ExpanderOptions.BreakOnNotEmpty) != ExpanderOptions.Invalid))
  883. {
  884. return true;
  885. }
  886. builder.Append(local.EvaluatedIncludeEscaped);
  887. builder.Append(str2);
  888. }
  889. }
  890. else
  891. {
  892. Stack<TransformFunction<P, I, S>> transformFunctionStack = Expander<P, I>.ItemExpander.PrepareTransformStackFromMatch<S>(elementLocation, match);
  893. foreach (Tuple<string, S> tuple in Expander<P, I>.ItemExpander.Transform<S>(expander, true, transformFunctionStack, IntrinsicItemFunctions<P, I, S>.GetItemTupleEnumerator(itemsOfType)))
  894. {
  895. if (((tuple.Item1 != null) && (tuple.Item1.Length > 0)) && ((options & ExpanderOptions.BreakOnNotEmpty) != ExpanderOptions.Invalid))
  896. {
  897. return true;
  898. }
  899. if (tuple.Item1 != null)
  900. {
  901. builder.Append(tuple.Item1);
  902. }
  903. builder.Append(str2);
  904. }
  905. }
  906. if (builder.Length > 0)
  907. {
  908. builder.Remove(builder.Length - str2.Length, str2.Length);
  909. }
  910. }
  911. return false;
  912. }
  913. internal static string ExpandItemVectorsIntoString<T>(Expander<P, I> expander, string expression, IItemProvider<T> items, ExpanderOptions options, IElementLocation elementLocation) where T: class, IItem
  914. {
  915. if (((options & ExpanderOptions.ExpandItems) == ExpanderOptions.Invalid) || (expression.Length == 0))
  916. {
  917. return expression;
  918. }
  919. ErrorUtilities.VerifyThrow(items != null, "Cannot expand items without providing items");
  920. List<ExpressionShredder.ItemExpressionCapture> referencedItemExpressions = ExpressionShredder.GetReferencedItemExpressions(expression);
  921. if (referencedItemExpressions == null)
  922. {
  923. return expression;
  924. }
  925. StringBuilder builder = new StringBuilder();
  926. int startIndex = 0;
  927. for (int i = 0; i < referencedItemExpressions.Count; i++)
  928. {
  929. if (referencedItemExpressions[i].Index > startIndex)
  930. {
  931. if ((options & ExpanderOptions.BreakOnNotEmpty) != ExpanderOptions.Invalid)
  932. {
  933. return null;
  934. }
  935. builder.Append(expression, startIndex, referencedItemExpressions[i].Index - startIndex);
  936. }
  937. if (Expander<P, I>.ItemExpander.ExpandItemVectorMatchIntoStringBuilder<T>(expander, referencedItemExpressions[i], items, elementLocation, builder, options))
  938. {
  939. return null;
  940. }
  941. startIndex = referencedItemExpressions[i].Index + referencedItemExpressions[i].Length;
  942. }
  943. builder.Append(expression, startIndex, expression.Length - startIndex);
  944. return OpportunisticIntern.StringBuilderToString(builder);
  945. }
  946. internal static IList<T> ExpandSingleItemVectorExpressionIntoItems<S, T>(Expander<P, I> expander, string expression, IItemProvider<S> items, IItemFactory<S, T> itemFactory, ExpanderOptions options, bool includeNullEntries, out bool isTransformExpression, IElementLocation elementLocation) where S: class, IItem where T: class, IItem
  947. {
  948. isTransformExpression = false;
  949. if (((options & ExpanderOptions.ExpandItems) == ExpanderOptions.Invalid) || (expression.Length == 0))
  950. {
  951. return null;
  952. }
  953. ErrorUtilities.VerifyThrow(items != null, "Cannot expand items without providing items");
  954. List<ExpressionShredder.ItemExpressionCapture> referencedItemExpressions = null;
  955. if (Expander<P, I>.invariantCompareInfo.IndexOf(expression, '@') == -1)
  956. {
  957. return null;
  958. }
  959. referencedItemExpressions = ExpressionShredder.GetReferencedItemExpressions(expression);
  960. if (referencedItemExpressions == null)
  961. {
  962. return null;
  963. }
  964. ExpressionShredder.ItemExpressionCapture match = referencedItemExpressions[0];
  965. ProjectErrorUtilities.VerifyThrowInvalidProject(match.Value == expression, elementLocation, "EmbeddedItemVectorCannotBeItemized", expression);
  966. ErrorUtilities.VerifyThrow(referencedItemExpressions.Count == 1, "Expected just one item vector");
  967. if (itemFactory.ItemType == null)
  968. {
  969. itemFactory.ItemType = match.ItemType;
  970. }
  971. IList<T> list2 = null;
  972. if (match.Separator != null)
  973. {
  974. StringBuilder builder = new StringBuilder();
  975. if (Expander<P, I>.ItemExpander.ExpandItemVectorMatchIntoStringBuilder<S>(expander, match, items, elementLocation, builder, options))
  976. {
  977. return null;
  978. }
  979. string include = OpportunisticIntern.StringBuilderToString(builder);
  980. list2 = new List<T>(1);
  981. if (include.Length > 0)
  982. {
  983. T item = itemFactory.CreateItem(include);
  984. list2.Add(item);
  985. }
  986. return list2;
  987. }
  988. if (match.Captures != null)
  989. {
  990. isTransformExpression = true;
  991. }
  992. ICollection<S> itemsOfType = items.GetItems(match.ItemType);
  993. if (itemsOfType.Count == 0)
  994. {
  995. return new List<T>();
  996. }
  997. list2 = new List<T>(itemsOfType.Count);
  998. if (!isTransformExpression)
  999. {
  1000. foreach (S local2 in itemsOfType)
  1001. {
  1002. if ((options & ExpanderOptions.BreakOnNotEmpty) != ExpanderOptions.Invalid)
  1003. {
  1004. return null;
  1005. }
  1006. T local3 = itemFactory.CreateItem(local2);
  1007. list2.Add(local3);
  1008. }
  1009. return list2;
  1010. }
  1011. Stack<TransformFunction<P, I, S>> transformFunctionStack = Expander<P, I>.ItemExpander.PrepareTransformStackFromMatch<S>(elementLocation, match);
  1012. foreach (Tuple<string, S> tuple in Expander<P, I>.ItemExpander.Transform<S>(expander, includeNullEntries, transformFunctionStack, IntrinsicItemFunctions<P, I, S>.GetItemTupleEnumerator(itemsOfType)))
  1013. {
  1014. if ((tuple.Item1 != null) && (tuple.Item2 == null))
  1015. {
  1016. list2.Add(itemFactory.CreateItem(tuple.Item1));
  1017. }
  1018. else
  1019. {
  1020. if ((tuple.Item1 != null) && (tuple.Item2 != null))
  1021. {
  1022. list2.Add(itemFactory.CreateItem(tuple.Item1, tuple.Item2));
  1023. continue;
  1024. }
  1025. if (includeNullEntries)
  1026. {
  1027. T local4 = default(T);
  1028. list2.Add(local4);
  1029. }
  1030. }
  1031. }
  1032. return list2;
  1033. }
  1034. private static Stack<TransformFunction<P, I, S>> PrepareTransformStackFromMatch<S>(IElementLocation elementLocation, ExpressionShredder.ItemExpressionCapture match) where S: class, IItem
  1035. {
  1036. ProjectErrorUtilities.VerifyThrowInvalidProject(match.Captures.Count > 0, elementLocation, "InvalidFunctionPropertyExpression");
  1037. Stack<TransformFunction<P, I, S>> stack = new Stack<TransformFunction<P, I, S>>(match.Captures.Count);
  1038. for (int i = match.Captures.Count - 1; i >= 0; i--)
  1039. {
  1040. string str = match.Captures[i].Value;
  1041. string functionName = match.Captures[i].FunctionName;
  1042. string functionArguments = match.Captures[i].FunctionArguments;
  1043. string[] arguments = null;
  1044. if (functionName == null)
  1045. {
  1046. functionName = "ExpandQuotedExpressionFunction";
  1047. arguments = new string[] { str };
  1048. }
  1049. else if (functionArguments != null)
  1050. {
  1051. arguments = Expander<P, I>.ExtractFunctionArguments(elementLocation, functionArguments, functionArguments);
  1052. }
  1053. IntrinsicItemFunctions<P, I, S>.ItemTransformFunction transform = IntrinsicItemFunctions<P, I, S>.GetItemTransformFunction(elementLocation, functionName, typeof(S));
  1054. stack.Push(new TransformFunction<P, I, S>(elementLocation, functionName, transform, arguments));
  1055. }
  1056. return stack;
  1057. }
  1058. internal static IEnumerable<Tuple<string, S>> Transform<S>(Expander<P, I> expander, bool includeNullEntries, Stack<TransformFunction<P, I, S>> transformFunctionStack, IEnumerable<Tuple<string, S>> itemsOfType) where S: class, IItem
  1059. {
  1060. if (this.transformFunctionStack.Count > 0)
  1061. {
  1062. TransformFunction<P, I, S> iteratorVariable0 = this.transformFunctionStack.Pop();
  1063. IEnumerator<Tuple<string, S>> enumerator = Expander<P, I>.ItemExpander.Transform<S>(this.expander, this.includeNullEntries, this.transformFunctionStack, iteratorVariable0.Execute(this.expander, this.includeNullEntries, this.itemsOfType)).GetEnumerator();
  1064. while (enumerator.MoveNext())
  1065. {
  1066. Tuple<string, S> current = enumerator.Current;
  1067. yield return current;
  1068. }
  1069. this.<>m__Finally5();
  1070. }
  1071. else
  1072. {
  1073. IEnumerator<Tuple<string, S>> iteratorVariable4 = this.itemsOfType.GetEnumerator();
  1074. while (iteratorVariable4.MoveNext())
  1075. {
  1076. Tuple<string, S> iteratorVariable2 = iteratorVariable4.Current;
  1077. yield return iteratorVariable2;
  1078. }
  1079. this.<>m__Finally7();
  1080. }
  1081. }
  1082. [CompilerGenerated]
  1083. private sealed class <Transform>d__0<S> : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable where S: class, IItem
  1084. {
  1085. private int <>1__state;
  1086. private Tuple<string, S> <>2__current;
  1087. public Expander<P, I> <>3__expander;
  1088. public bool <>3__includeNullEntries;
  1089. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  1090. public Stack<Expander<P, I>.ItemExpander.TransformFunction<S>> <>3__transformFunctionStack;
  1091. public IEnumerator<Tuple<string, S>> <>7__wrap4;
  1092. public IEnumerator<Tuple<string, S>> <>7__wrap6;
  1093. private int <>l__initialThreadId;
  1094. public Expander<P, I>.ItemExpander.TransformFunction<S> <function>5__1;
  1095. public Tuple<string, S> <item>5__2;
  1096. public Tuple<string, S> <item>5__3;
  1097. public Expander<P, I> expander;
  1098. public bool includeNullEntries;
  1099. public IEnumerable<Tuple<string, S>> itemsOfType;
  1100. public Stack<Expander<P, I>.ItemExpander.TransformFunction<S>> transformFunctionStack;
  1101. [DebuggerHidden]
  1102. public <Transform>d__0(int <>1__state)
  1103. {
  1104. this.<>1__state = <>1__state;
  1105. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  1106. }
  1107. private void <>m__Finally5()
  1108. {
  1109. this.<>1__state = -1;
  1110. if (this.<>7__wrap4 != null)
  1111. {
  1112. this.<>7__wrap4.Dispose();
  1113. }
  1114. }
  1115. private void <>m__Finally7()
  1116. {
  1117. this.<>1__state = -1;
  1118. if (this.<>7__wrap6 != null)
  1119. {
  1120. this.<>7__wrap6.Dispose();
  1121. }
  1122. }
  1123. private bool MoveNext()
  1124. {
  1125. bool flag;
  1126. try
  1127. {
  1128. switch (this.<>1__state)
  1129. {
  1130. case 0:
  1131. this.<>1__state = -1;
  1132. if (this.transformFunctionStack.Count <= 0)
  1133. {
  1134. goto Label_00DE;
  1135. }
  1136. this.<function>5__1 = this.transformFunctionStack.Pop();
  1137. this.<>7__wrap4 = Expander<P, I>.ItemExpander.Transform<S>(this.expander, this.includeNullEntries, this.transformFunctionStack, this.<function>5__1.Execute(this.expander, this.includeNullEntries, this.itemsOfType)).GetEnumerator();
  1138. this.<>1__state = 1;
  1139. goto Label_00C9;
  1140. case 2:
  1141. this.<>1__state = 1;
  1142. goto Label_00C9;
  1143. case 4:
  1144. goto Label_0120;
  1145. default:
  1146. goto Label_013A;
  1147. }
  1148. Label_0097:
  1149. this.<item>5__2 = this.<>7__wrap4.Current;
  1150. this.<>2__current = this.<item>5__2;
  1151. this.<>1__state = 2;
  1152. return true;
  1153. Label_00C9:
  1154. if (this.<>7__wrap4.MoveNext())
  1155. {
  1156. goto Label_0097;
  1157. }
  1158. this.<>m__Finally5();
  1159. goto Label_013A;
  1160. Label_00DE:
  1161. this.<>7__wrap6 = this.itemsOfType.GetEnumerator();
  1162. this.<>1__state = 3;
  1163. while (this.<>7__wrap6.MoveNext())
  1164. {
  1165. this.<item>5__3 = this.<>7__wrap6.Current;
  1166. this.<>2__current = this.<item>5__3;
  1167. this.<>1__state = 4;
  1168. return true;
  1169. Label_0120:
  1170. this.<>1__state = 3;
  1171. }
  1172. this.<>m__Finally7();
  1173. Label_013A:
  1174. flag = false;
  1175. }
  1176. fault
  1177. {
  1178. this.System.IDisposable.Dispose();
  1179. }
  1180. return flag;
  1181. }
  1182. [DebuggerHidden]
  1183. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  1184. {
  1185. Expander<P, I>.ItemExpander.<Transform>d__0<S> d__;
  1186. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  1187. {
  1188. this.<>1__state = 0;
  1189. d__ = (Expander<P, I>.ItemExpander.<Transform>d__0<S>) this;
  1190. }
  1191. else
  1192. {
  1193. d__ = new Expander<P, I>.ItemExpander.<Transform>d__0<S>(0);
  1194. }
  1195. d__.expander = this.<>3__expander;
  1196. d__.includeNullEntries = this.<>3__includeNullEntries;
  1197. d__.transformFunctionStack = this.<>3__transformFunctionStack;
  1198. d__.itemsOfType = this.<>3__itemsOfType;
  1199. return d__;
  1200. }
  1201. [DebuggerHidden]
  1202. IEnumerator IEnumerable.GetEnumerator()
  1203. {
  1204. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  1205. }
  1206. [DebuggerHidden]
  1207. void IEnumerator.Reset()
  1208. {
  1209. throw new NotSupportedException();
  1210. }
  1211. void IDisposable.Dispose()
  1212. {
  1213. switch (this.<>1__state)
  1214. {
  1215. case 1:
  1216. case 2:
  1217. try
  1218. {
  1219. }
  1220. finally
  1221. {
  1222. this.<>m__Finally5();
  1223. }
  1224. break;
  1225. case 3:
  1226. case 4:
  1227. try
  1228. {
  1229. }
  1230. finally
  1231. {
  1232. this.<>m__Finally7();
  1233. }
  1234. return;
  1235. }
  1236. }
  1237. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  1238. {
  1239. [DebuggerHidden]
  1240. get
  1241. {
  1242. return this.<>2__current;
  1243. }
  1244. }
  1245. object IEnumerator.Current
  1246. {
  1247. [DebuggerHidden]
  1248. get
  1249. {
  1250. return this.<>2__current;
  1251. }
  1252. }
  1253. }
  1254. internal static class IntrinsicItemFunctions<S> where S: class, IItem
  1255. {
  1256. private static ConcurrentDictionary<string, ItemTransformFunction<P, I, S>> transformFunctionDelegateCache;
  1257. static IntrinsicItemFunctions()
  1258. {
  1259. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.transformFunctionDelegateCache = new ConcurrentDictionary<string, ItemTransformFunction<P, I, S>>(StringComparer.OrdinalIgnoreCase);
  1260. }
  1261. internal static IEnumerable<Tuple<string, S>> AnyHaveMetadataValue(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1262. {
  1263. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments != null) && (arguments.Length == 2), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1264. string name = arguments[0];
  1265. string b = arguments[1];
  1266. bool iteratorVariable2 = false;
  1267. foreach (Tuple<string, S> iteratorVariable3 in itemsOfType)
  1268. {
  1269. if (iteratorVariable3.Item2 != null)
  1270. {
  1271. string metadataValue = iteratorVariable3.Item2.GetMetadataValue(name);
  1272. if ((metadataValue != null) && string.Equals(metadataValue, b, StringComparison.OrdinalIgnoreCase))
  1273. {
  1274. iteratorVariable2 = true;
  1275. yield return new Tuple<string, S>("true", iteratorVariable3.Item2);
  1276. goto Label_017E;
  1277. }
  1278. }
  1279. }
  1280. if (!iteratorVariable2)
  1281. {
  1282. yield return new Tuple<string, S>("false", default(S));
  1283. }
  1284. Label_017E:
  1285. yield break;
  1286. }
  1287. internal static IEnumerable<Tuple<string, S>> ClearMetadata(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1288. {
  1289. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments == null) || (arguments.Length == 0), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1290. foreach (Tuple<string, S> iteratorVariable0 in itemsOfType)
  1291. {
  1292. if (includeNullEntries || (iteratorVariable0.Item1 != null))
  1293. {
  1294. yield return new Tuple<string, S>(iteratorVariable0.Item1, default(S));
  1295. }
  1296. }
  1297. }
  1298. internal static IEnumerable<Tuple<string, S>> DirectoryName(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1299. {
  1300. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments == null) || (arguments.Length == 0), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1301. Dictionary<string, string> iteratorVariable0 = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  1302. foreach (Tuple<string, S> iteratorVariable1 in itemsOfType)
  1303. {
  1304. if (!string.IsNullOrEmpty(iteratorVariable1.Item1))
  1305. {
  1306. string directoryName = null;
  1307. if (!iteratorVariable0.TryGetValue(iteratorVariable1.Item1, out directoryName))
  1308. {
  1309. string path = EscapingUtilities.UnescapeAll(iteratorVariable1.Item1);
  1310. try
  1311. {
  1312. string str2;
  1313. if (Path.IsPathRooted(path))
  1314. {
  1315. str2 = path;
  1316. }
  1317. else
  1318. {
  1319. string str3 = iteratorVariable1.Item2.ProjectDirectory ?? string.Empty;
  1320. str2 = Path.Combine(str3, path);
  1321. }
  1322. directoryName = Path.GetDirectoryName(str2);
  1323. }
  1324. catch (Exception exception)
  1325. {
  1326. if (ExceptionHandling.NotExpectedException(exception))
  1327. {
  1328. throw;
  1329. }
  1330. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidItemFunctionExpression", functionName, iteratorVariable1.Item1, exception.Message);
  1331. }
  1332. directoryName = EscapingUtilities.Escape(directoryName);
  1333. iteratorVariable0[path] = directoryName;
  1334. }
  1335. if (!string.IsNullOrEmpty(directoryName))
  1336. {
  1337. yield return new Tuple<string, S>(directoryName, iteratorVariable1.Item2);
  1338. }
  1339. else if (includeNullEntries)
  1340. {
  1341. yield return new Tuple<string, S>(null, iteratorVariable1.Item2);
  1342. }
  1343. }
  1344. }
  1345. }
  1346. internal static IEnumerable<Tuple<string, S>> Distinct(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1347. {
  1348. return Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.DistinctWithComparer(expander, elementLocation, includeNullEntries, functionName, itemsOfType, arguments, StringComparer.OrdinalIgnoreCase);
  1349. }
  1350. internal static IEnumerable<Tuple<string, S>> DistinctWithCase(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1351. {
  1352. return Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.DistinctWithComparer(expander, elementLocation, includeNullEntries, functionName, itemsOfType, arguments, StringComparer.Ordinal);
  1353. }
  1354. internal static IEnumerable<Tuple<string, S>> DistinctWithComparer(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments, StringComparer comparer)
  1355. {
  1356. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments == null) || (arguments.Length == 0), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1357. Dictionary<string, S> iteratorVariable0 = new Dictionary<string, S>(comparer);
  1358. foreach (Tuple<string, S> iteratorVariable1 in itemsOfType)
  1359. {
  1360. if ((iteratorVariable1.Item1 != null) && !iteratorVariable0.ContainsKey(iteratorVariable1.Item1))
  1361. {
  1362. iteratorVariable0[iteratorVariable1.Item1] = iteratorVariable1.Item2;
  1363. yield return new Tuple<string, S>(iteratorVariable1.Item1, iteratorVariable1.Item2);
  1364. }
  1365. }
  1366. }
  1367. internal static IEnumerable<Tuple<string, S>> ExecuteStringFunction(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1368. {
  1369. foreach (Tuple<string, S> iteratorVariable0 in itemsOfType)
  1370. {
  1371. object valueToConvert = new Expander<P, I>.Function<P>(typeof(string), iteratorVariable0.Item1, iteratorVariable0.Item1, functionName, arguments, BindingFlags.InvokeMethod | BindingFlags.Public, string.Empty, expander.UsedUninitializedProperties).Execute(iteratorVariable0.Item1, expander.properties, ExpanderOptions.ExpandAll, elementLocation);
  1372. string iteratorVariable3 = Expander<P, I>.PropertyExpander<P>.ConvertToString(valueToConvert);
  1373. if (iteratorVariable3.Length > 0)
  1374. {
  1375. yield return new Tuple<string, S>(iteratorVariable3, iteratorVariable0.Item2);
  1376. }
  1377. else if (includeNullEntries)
  1378. {
  1379. yield return new Tuple<string, S>(null, iteratorVariable0.Item2);
  1380. }
  1381. }
  1382. }
  1383. internal static IEnumerable<Tuple<string, S>> ExpandQuotedExpressionFunction(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1384. {
  1385. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments != null) && (arguments.Length == 1), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1386. foreach (Tuple<string, S> iteratorVariable0 in itemsOfType)
  1387. {
  1388. string iteratorVariable2 = null;
  1389. if (iteratorVariable0.Item1 != null)
  1390. {
  1391. Expander<P, I>.ItemExpander.MetadataMatchEvaluator iteratorVariable1 = new Expander<P, I>.ItemExpander.MetadataMatchEvaluator(iteratorVariable0.Item1, iteratorVariable0.Item2, elementLocation);
  1392. iteratorVariable2 = Expander<P, I>.RegularExpressions.ItemMetadataPattern.Replace(arguments[0], new MatchEvaluator(iteratorVariable1.GetMetadataValueFromMatch));
  1393. }
  1394. if ((iteratorVariable2 != null) && (iteratorVariable2.Length > 0))
  1395. {
  1396. yield return new Tuple<string, S>(iteratorVariable2, iteratorVariable0.Item2);
  1397. }
  1398. else if (includeNullEntries)
  1399. {
  1400. yield return new Tuple<string, S>(null, iteratorVariable0.Item2);
  1401. }
  1402. }
  1403. }
  1404. internal static ItemTransformFunction<P, I, S> GetItemTransformFunction(IElementLocation elementLocation, string functionName, Type itemType)
  1405. {
  1406. ItemTransformFunction<P, I, S> function = null;
  1407. string key = itemType.FullName + "::" + functionName;
  1408. if (!Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.transformFunctionDelegateCache.TryGetValue(key, out function))
  1409. {
  1410. if (FileUtilities.ItemSpecModifiers.IsDerivableItemSpecModifier(functionName))
  1411. {
  1412. function = new ItemTransformFunction<P, I, S>(Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.ItemSpecModifierFunction);
  1413. }
  1414. else
  1415. {
  1416. MethodInfo method = typeof(Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>).GetMethod(functionName, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
  1417. if (method == null)
  1418. {
  1419. functionName = "ExecuteStringFunction";
  1420. method = typeof(Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>).GetMethod(functionName, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
  1421. if (method == null)
  1422. {
  1423. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "UnknownItemFunction", functionName);
  1424. return null;
  1425. }
  1426. function = (ItemTransformFunction<P, I, S>) Delegate.CreateDelegate(typeof(ItemTransformFunction<P, I, S>), method, false);
  1427. }
  1428. else
  1429. {
  1430. function = (ItemTransformFunction<P, I, S>) Delegate.CreateDelegate(typeof(ItemTransformFunction<P, I, S>), method, false);
  1431. }
  1432. }
  1433. if (function == null)
  1434. {
  1435. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "UnknownItemFunction", functionName);
  1436. return null;
  1437. }
  1438. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.transformFunctionDelegateCache[key] = function;
  1439. }
  1440. return function;
  1441. }
  1442. internal static IEnumerable<Tuple<string, S>> GetItemTupleEnumerator(IEnumerable<S> itemsOfType)
  1443. {
  1444. foreach (S iteratorVariable0 in itemsOfType)
  1445. {
  1446. yield return new Tuple<string, S>(iteratorVariable0.EvaluatedIncludeEscaped, iteratorVariable0);
  1447. }
  1448. }
  1449. internal static IEnumerable<Tuple<string, S>> ItemSpecModifierFunction(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1450. {
  1451. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments == null) || (arguments.Length == 0), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1452. CopyOnWriteDictionary<string, string> cachedModifiers = new CopyOnWriteDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  1453. foreach (Tuple<string, S> iteratorVariable1 in itemsOfType)
  1454. {
  1455. if (!string.IsNullOrEmpty(iteratorVariable1.Item1))
  1456. {
  1457. string iteratorVariable2 = null;
  1458. try
  1459. {
  1460. string currentDirectory = iteratorVariable1.Item2.ProjectDirectory ?? Directory.GetCurrentDirectory();
  1461. iteratorVariable2 = FileUtilities.ItemSpecModifiers.GetItemSpecModifier(currentDirectory, iteratorVariable1.Item1, functionName, ref cachedModifiers);
  1462. }
  1463. catch (Exception exception)
  1464. {
  1465. if (ExceptionHandling.NotExpectedException(exception))
  1466. {
  1467. throw;
  1468. }
  1469. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidItemFunctionExpression", functionName, iteratorVariable1.Item1, exception.Message);
  1470. }
  1471. if (!string.IsNullOrEmpty(iteratorVariable2))
  1472. {
  1473. yield return new Tuple<string, S>(iteratorVariable2, iteratorVariable1.Item2);
  1474. }
  1475. else if (includeNullEntries)
  1476. {
  1477. yield return new Tuple<string, S>(null, iteratorVariable1.Item2);
  1478. }
  1479. }
  1480. }
  1481. }
  1482. internal static IEnumerable<Tuple<string, S>> Metadata(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1483. {
  1484. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments != null) && (arguments.Length == 1), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1485. string name = arguments[0];
  1486. foreach (Tuple<string, S> iteratorVariable1 in itemsOfType)
  1487. {
  1488. if (iteratorVariable1.Item2 != null)
  1489. {
  1490. string metadataValueEscaped = iteratorVariable1.Item2.GetMetadataValueEscaped(name);
  1491. if (!string.IsNullOrEmpty(metadataValueEscaped))
  1492. {
  1493. if (Expander<P, I>.invariantCompareInfo.IndexOf(metadataValueEscaped, ';') < 0)
  1494. {
  1495. yield return new Tuple<string, S>(metadataValueEscaped, iteratorVariable1.Item2);
  1496. }
  1497. else
  1498. {
  1499. IList<string> iteratorVariable3 = ExpressionShredder.SplitSemiColonSeparatedList(metadataValueEscaped);
  1500. foreach (string iteratorVariable4 in iteratorVariable3)
  1501. {
  1502. yield return new Tuple<string, S>(iteratorVariable4, iteratorVariable1.Item2);
  1503. }
  1504. }
  1505. }
  1506. else if ((metadataValueEscaped != string.Empty) && includeNullEntries)
  1507. {
  1508. yield return new Tuple<string, S>(metadataValueEscaped, iteratorVariable1.Item2);
  1509. }
  1510. }
  1511. }
  1512. }
  1513. internal static IEnumerable<Tuple<string, S>> Reverse(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1514. {
  1515. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments == null) || (arguments.Length == 0), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1516. foreach (Tuple<string, S> iteratorVariable0 in itemsOfType.Reverse<Tuple<string, S>>())
  1517. {
  1518. yield return new Tuple<string, S>(iteratorVariable0.Item1, iteratorVariable0.Item2);
  1519. }
  1520. }
  1521. internal static IEnumerable<Tuple<string, S>> WithMetadataValue(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments)
  1522. {
  1523. ProjectErrorUtilities.VerifyThrowInvalidProject((arguments != null) && (arguments.Length == 2), elementLocation, "InvalidItemFunctionSyntax", functionName);
  1524. string name = arguments[0];
  1525. string b = arguments[1];
  1526. foreach (Tuple<string, S> iteratorVariable2 in itemsOfType)
  1527. {
  1528. string metadataValue = iteratorVariable2.Item2.GetMetadataValue(name);
  1529. if ((metadataValue != null) && string.Equals(metadataValue, b, StringComparison.OrdinalIgnoreCase))
  1530. {
  1531. yield return new Tuple<string, S>(iteratorVariable2.Item1, iteratorVariable2.Item2);
  1532. }
  1533. }
  1534. }
  1535. [CompilerGenerated]
  1536. private sealed class <AnyHaveMetadataValue>d__59 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  1537. {
  1538. private int <>1__state;
  1539. private Tuple<string, S> <>2__current;
  1540. public string[] <>3__arguments;
  1541. public IElementLocation <>3__elementLocation;
  1542. public string <>3__functionName;
  1543. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  1544. public IEnumerator<Tuple<string, S>> <>7__wrap5f;
  1545. private int <>l__initialThreadId;
  1546. public Tuple<string, S> <item>5__5d;
  1547. public bool <metadataFound>5__5c;
  1548. public string <metadataName>5__5a;
  1549. public string <metadataValue>5__5e;
  1550. public string <metadataValueToFind>5__5b;
  1551. public string[] arguments;
  1552. public IElementLocation elementLocation;
  1553. public string functionName;
  1554. public IEnumerable<Tuple<string, S>> itemsOfType;
  1555. [DebuggerHidden]
  1556. public <AnyHaveMetadataValue>d__59(int <>1__state)
  1557. {
  1558. this.<>1__state = <>1__state;
  1559. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  1560. }
  1561. private void <>m__Finally60()
  1562. {
  1563. this.<>1__state = -1;
  1564. if (this.<>7__wrap5f != null)
  1565. {
  1566. this.<>7__wrap5f.Dispose();
  1567. }
  1568. }
  1569. private bool MoveNext()
  1570. {
  1571. bool flag;
  1572. try
  1573. {
  1574. switch (this.<>1__state)
  1575. {
  1576. case 0:
  1577. this.<>1__state = -1;
  1578. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments != null) && (this.arguments.Length == 2), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  1579. this.<metadataName>5__5a = this.arguments[0];
  1580. this.<metadataValueToFind>5__5b = this.arguments[1];
  1581. this.<metadataFound>5__5c = false;
  1582. this.<>7__wrap5f = this.itemsOfType.GetEnumerator();
  1583. this.<>1__state = 1;
  1584. goto Label_0135;
  1585. case 2:
  1586. this.<>1__state = 1;
  1587. this.System.IDisposable.Dispose();
  1588. goto Label_017E;
  1589. case 3:
  1590. this.<>1__state = -1;
  1591. goto Label_017E;
  1592. default:
  1593. goto Label_017E;
  1594. }
  1595. Label_0095:
  1596. this.<item>5__5d = this.<>7__wrap5f.Current;
  1597. if (this.<item>5__5d.Item2 != null)
  1598. {
  1599. this.<metadataValue>5__5e = this.<item>5__5d.Item2.GetMetadataValue(this.<metadataName>5__5a);
  1600. if ((this.<metadataValue>5__5e != null) && string.Equals(this.<metadataValue>5__5e, this.<metadataValueToFind>5__5b, StringComparison.OrdinalIgnoreCase))
  1601. {
  1602. this.<metadataFound>5__5c = true;
  1603. this.<>2__current = new Tuple<string, S>("true", this.<item>5__5d.Item2);
  1604. this.<>1__state = 2;
  1605. return true;
  1606. }
  1607. }
  1608. Label_0135:
  1609. if (this.<>7__wrap5f.MoveNext())
  1610. {
  1611. goto Label_0095;
  1612. }
  1613. this.<>m__Finally60();
  1614. if (!this.<metadataFound>5__5c)
  1615. {
  1616. this.<>2__current = new Tuple<string, S>("false", default(S));
  1617. this.<>1__state = 3;
  1618. return true;
  1619. }
  1620. Label_017E:
  1621. flag = false;
  1622. }
  1623. fault
  1624. {
  1625. this.System.IDisposable.Dispose();
  1626. }
  1627. return flag;
  1628. }
  1629. [DebuggerHidden]
  1630. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  1631. {
  1632. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<AnyHaveMetadataValue>d__59 d__;
  1633. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  1634. {
  1635. this.<>1__state = 0;
  1636. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<AnyHaveMetadataValue>d__59) this;
  1637. }
  1638. else
  1639. {
  1640. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<AnyHaveMetadataValue>d__59(0);
  1641. }
  1642. d__.elementLocation = this.<>3__elementLocation;
  1643. d__.functionName = this.<>3__functionName;
  1644. d__.itemsOfType = this.<>3__itemsOfType;
  1645. d__.arguments = this.<>3__arguments;
  1646. return d__;
  1647. }
  1648. [DebuggerHidden]
  1649. IEnumerator IEnumerable.GetEnumerator()
  1650. {
  1651. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  1652. }
  1653. [DebuggerHidden]
  1654. void IEnumerator.Reset()
  1655. {
  1656. throw new NotSupportedException();
  1657. }
  1658. void IDisposable.Dispose()
  1659. {
  1660. switch (this.<>1__state)
  1661. {
  1662. case 1:
  1663. case 2:
  1664. try
  1665. {
  1666. }
  1667. finally
  1668. {
  1669. this.<>m__Finally60();
  1670. }
  1671. return;
  1672. }
  1673. }
  1674. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  1675. {
  1676. [DebuggerHidden]
  1677. get
  1678. {
  1679. return this.<>2__current;
  1680. }
  1681. }
  1682. object IEnumerator.Current
  1683. {
  1684. [DebuggerHidden]
  1685. get
  1686. {
  1687. return this.<>2__current;
  1688. }
  1689. }
  1690. }
  1691. [CompilerGenerated]
  1692. private sealed class <ClearMetadata>d__4a : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  1693. {
  1694. private int <>1__state;
  1695. private Tuple<string, S> <>2__current;
  1696. public string[] <>3__arguments;
  1697. public IElementLocation <>3__elementLocation;
  1698. public string <>3__functionName;
  1699. public bool <>3__includeNullEntries;
  1700. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  1701. public IEnumerator<Tuple<string, S>> <>7__wrap4c;
  1702. private int <>l__initialThreadId;
  1703. public Tuple<string, S> <item>5__4b;
  1704. public string[] arguments;
  1705. public IElementLocation elementLocation;
  1706. public string functionName;
  1707. public bool includeNullEntries;
  1708. public IEnumerable<Tuple<string, S>> itemsOfType;
  1709. [DebuggerHidden]
  1710. public <ClearMetadata>d__4a(int <>1__state)
  1711. {
  1712. this.<>1__state = <>1__state;
  1713. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  1714. }
  1715. private void <>m__Finally4d()
  1716. {
  1717. this.<>1__state = -1;
  1718. if (this.<>7__wrap4c != null)
  1719. {
  1720. this.<>7__wrap4c.Dispose();
  1721. }
  1722. }
  1723. private bool MoveNext()
  1724. {
  1725. bool flag;
  1726. try
  1727. {
  1728. switch (this.<>1__state)
  1729. {
  1730. case 0:
  1731. this.<>1__state = -1;
  1732. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments == null) || (this.arguments.Length == 0), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  1733. this.<>7__wrap4c = this.itemsOfType.GetEnumerator();
  1734. this.<>1__state = 1;
  1735. goto Label_00C2;
  1736. case 2:
  1737. this.<>1__state = 1;
  1738. goto Label_00C2;
  1739. default:
  1740. goto Label_00D5;
  1741. }
  1742. Label_006B:
  1743. this.<item>5__4b = this.<>7__wrap4c.Current;
  1744. if (this.includeNullEntries || (this.<item>5__4b.Item1 != null))
  1745. {
  1746. this.<>2__current = new Tuple<string, S>(this.<item>5__4b.Item1, default(S));
  1747. this.<>1__state = 2;
  1748. return true;
  1749. }
  1750. Label_00C2:
  1751. if (this.<>7__wrap4c.MoveNext())
  1752. {
  1753. goto Label_006B;
  1754. }
  1755. this.<>m__Finally4d();
  1756. Label_00D5:
  1757. flag = false;
  1758. }
  1759. fault
  1760. {
  1761. this.System.IDisposable.Dispose();
  1762. }
  1763. return flag;
  1764. }
  1765. [DebuggerHidden]
  1766. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  1767. {
  1768. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ClearMetadata>d__4a d__a;
  1769. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  1770. {
  1771. this.<>1__state = 0;
  1772. d__a = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ClearMetadata>d__4a) this;
  1773. }
  1774. else
  1775. {
  1776. d__a = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ClearMetadata>d__4a(0);
  1777. }
  1778. d__a.elementLocation = this.<>3__elementLocation;
  1779. d__a.includeNullEntries = this.<>3__includeNullEntries;
  1780. d__a.functionName = this.<>3__functionName;
  1781. d__a.itemsOfType = this.<>3__itemsOfType;
  1782. d__a.arguments = this.<>3__arguments;
  1783. return d__a;
  1784. }
  1785. [DebuggerHidden]
  1786. IEnumerator IEnumerable.GetEnumerator()
  1787. {
  1788. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  1789. }
  1790. [DebuggerHidden]
  1791. void IEnumerator.Reset()
  1792. {
  1793. throw new NotSupportedException();
  1794. }
  1795. void IDisposable.Dispose()
  1796. {
  1797. switch (this.<>1__state)
  1798. {
  1799. case 1:
  1800. case 2:
  1801. try
  1802. {
  1803. }
  1804. finally
  1805. {
  1806. this.<>m__Finally4d();
  1807. }
  1808. return;
  1809. }
  1810. }
  1811. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  1812. {
  1813. [DebuggerHidden]
  1814. get
  1815. {
  1816. return this.<>2__current;
  1817. }
  1818. }
  1819. object IEnumerator.Current
  1820. {
  1821. [DebuggerHidden]
  1822. get
  1823. {
  1824. return this.<>2__current;
  1825. }
  1826. }
  1827. }
  1828. [CompilerGenerated]
  1829. private sealed class <DirectoryName>d__18 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  1830. {
  1831. private int <>1__state;
  1832. private Tuple<string, S> <>2__current;
  1833. public string[] <>3__arguments;
  1834. public IElementLocation <>3__elementLocation;
  1835. public string <>3__functionName;
  1836. public bool <>3__includeNullEntries;
  1837. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  1838. public IEnumerator<Tuple<string, S>> <>7__wrap1c;
  1839. private int <>l__initialThreadId;
  1840. public string <directoryName>5__1b;
  1841. public Dictionary<string, string> <directoryNameTable>5__19;
  1842. public Tuple<string, S> <item>5__1a;
  1843. public string[] arguments;
  1844. public IElementLocation elementLocation;
  1845. public string functionName;
  1846. public bool includeNullEntries;
  1847. public IEnumerable<Tuple<string, S>> itemsOfType;
  1848. [DebuggerHidden]
  1849. public <DirectoryName>d__18(int <>1__state)
  1850. {
  1851. this.<>1__state = <>1__state;
  1852. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  1853. }
  1854. private void <>m__Finally1d()
  1855. {
  1856. this.<>1__state = -1;
  1857. if (this.<>7__wrap1c != null)
  1858. {
  1859. this.<>7__wrap1c.Dispose();
  1860. }
  1861. }
  1862. private bool MoveNext()
  1863. {
  1864. bool flag;
  1865. try
  1866. {
  1867. switch (this.<>1__state)
  1868. {
  1869. case 0:
  1870. this.<>1__state = -1;
  1871. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments == null) || (this.arguments.Length == 0), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  1872. this.<directoryNameTable>5__19 = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  1873. this.<>7__wrap1c = this.itemsOfType.GetEnumerator();
  1874. this.<>1__state = 1;
  1875. goto Label_01F4;
  1876. case 3:
  1877. this.<>1__state = 1;
  1878. goto Label_01F4;
  1879. case 4:
  1880. this.<>1__state = 1;
  1881. goto Label_01F4;
  1882. default:
  1883. goto Label_020A;
  1884. }
  1885. Label_0088:
  1886. this.<item>5__1a = this.<>7__wrap1c.Current;
  1887. if (!string.IsNullOrEmpty(this.<item>5__1a.Item1))
  1888. {
  1889. this.<directoryName>5__1b = null;
  1890. if (!this.<directoryNameTable>5__19.TryGetValue(this.<item>5__1a.Item1, out this.<directoryName>5__1b))
  1891. {
  1892. string path = EscapingUtilities.UnescapeAll(this.<item>5__1a.Item1);
  1893. try
  1894. {
  1895. string str2;
  1896. if (Path.IsPathRooted(path))
  1897. {
  1898. str2 = path;
  1899. }
  1900. else
  1901. {
  1902. string str3 = this.<item>5__1a.Item2.ProjectDirectory ?? string.Empty;
  1903. str2 = Path.Combine(str3, path);
  1904. }
  1905. this.<directoryName>5__1b = Path.GetDirectoryName(str2);
  1906. }
  1907. catch (Exception exception)
  1908. {
  1909. if (ExceptionHandling.NotExpectedException(exception))
  1910. {
  1911. throw;
  1912. }
  1913. ProjectErrorUtilities.ThrowInvalidProject(this.elementLocation, "InvalidItemFunctionExpression", this.functionName, this.<item>5__1a.Item1, exception.Message);
  1914. }
  1915. this.<directoryName>5__1b = EscapingUtilities.Escape(this.<directoryName>5__1b);
  1916. this.<directoryNameTable>5__19[path] = this.<directoryName>5__1b;
  1917. }
  1918. if (!string.IsNullOrEmpty(this.<directoryName>5__1b))
  1919. {
  1920. this.<>2__current = new Tuple<string, S>(this.<directoryName>5__1b, this.<item>5__1a.Item2);
  1921. this.<>1__state = 3;
  1922. return true;
  1923. }
  1924. if (this.includeNullEntries)
  1925. {
  1926. this.<>2__current = new Tuple<string, S>(null, this.<item>5__1a.Item2);
  1927. this.<>1__state = 4;
  1928. return true;
  1929. }
  1930. }
  1931. Label_01F4:
  1932. if (this.<>7__wrap1c.MoveNext())
  1933. {
  1934. goto Label_0088;
  1935. }
  1936. this.<>m__Finally1d();
  1937. Label_020A:
  1938. flag = false;
  1939. }
  1940. fault
  1941. {
  1942. this.System.IDisposable.Dispose();
  1943. }
  1944. return flag;
  1945. }
  1946. [DebuggerHidden]
  1947. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  1948. {
  1949. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DirectoryName>d__18 d__;
  1950. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  1951. {
  1952. this.<>1__state = 0;
  1953. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DirectoryName>d__18) this;
  1954. }
  1955. else
  1956. {
  1957. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DirectoryName>d__18(0);
  1958. }
  1959. d__.elementLocation = this.<>3__elementLocation;
  1960. d__.includeNullEntries = this.<>3__includeNullEntries;
  1961. d__.functionName = this.<>3__functionName;
  1962. d__.itemsOfType = this.<>3__itemsOfType;
  1963. d__.arguments = this.<>3__arguments;
  1964. return d__;
  1965. }
  1966. [DebuggerHidden]
  1967. IEnumerator IEnumerable.GetEnumerator()
  1968. {
  1969. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  1970. }
  1971. [DebuggerHidden]
  1972. void IEnumerator.Reset()
  1973. {
  1974. throw new NotSupportedException();
  1975. }
  1976. void IDisposable.Dispose()
  1977. {
  1978. switch (this.<>1__state)
  1979. {
  1980. case 1:
  1981. case 3:
  1982. case 4:
  1983. try
  1984. {
  1985. }
  1986. finally
  1987. {
  1988. this.<>m__Finally1d();
  1989. }
  1990. break;
  1991. case 2:
  1992. break;
  1993. default:
  1994. return;
  1995. }
  1996. }
  1997. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  1998. {
  1999. [DebuggerHidden]
  2000. get
  2001. {
  2002. return this.<>2__current;
  2003. }
  2004. }
  2005. object IEnumerator.Current
  2006. {
  2007. [DebuggerHidden]
  2008. get
  2009. {
  2010. return this.<>2__current;
  2011. }
  2012. }
  2013. }
  2014. [CompilerGenerated]
  2015. private sealed class <DistinctWithComparer>d__2c : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2016. {
  2017. private int <>1__state;
  2018. private Tuple<string, S> <>2__current;
  2019. public string[] <>3__arguments;
  2020. public StringComparer <>3__comparer;
  2021. public IElementLocation <>3__elementLocation;
  2022. public string <>3__functionName;
  2023. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2024. public IEnumerator<Tuple<string, S>> <>7__wrap2f;
  2025. private int <>l__initialThreadId;
  2026. public Tuple<string, S> <item>5__2e;
  2027. public Dictionary<string, S> <seenItems>5__2d;
  2028. public string[] arguments;
  2029. public StringComparer comparer;
  2030. public IElementLocation elementLocation;
  2031. public string functionName;
  2032. public IEnumerable<Tuple<string, S>> itemsOfType;
  2033. [DebuggerHidden]
  2034. public <DistinctWithComparer>d__2c(int <>1__state)
  2035. {
  2036. this.<>1__state = <>1__state;
  2037. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2038. }
  2039. private void <>m__Finally30()
  2040. {
  2041. this.<>1__state = -1;
  2042. if (this.<>7__wrap2f != null)
  2043. {
  2044. this.<>7__wrap2f.Dispose();
  2045. }
  2046. }
  2047. private bool MoveNext()
  2048. {
  2049. bool flag;
  2050. try
  2051. {
  2052. switch (this.<>1__state)
  2053. {
  2054. case 0:
  2055. this.<>1__state = -1;
  2056. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments == null) || (this.arguments.Length == 0), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  2057. this.<seenItems>5__2d = new Dictionary<string, S>(this.comparer);
  2058. this.<>7__wrap2f = this.itemsOfType.GetEnumerator();
  2059. this.<>1__state = 1;
  2060. goto Label_0109;
  2061. case 2:
  2062. this.<>1__state = 1;
  2063. goto Label_0109;
  2064. default:
  2065. goto Label_011F;
  2066. }
  2067. Label_007F:
  2068. this.<item>5__2e = this.<>7__wrap2f.Current;
  2069. if ((this.<item>5__2e.Item1 != null) && !this.<seenItems>5__2d.ContainsKey(this.<item>5__2e.Item1))
  2070. {
  2071. this.<seenItems>5__2d[this.<item>5__2e.Item1] = this.<item>5__2e.Item2;
  2072. this.<>2__current = new Tuple<string, S>(this.<item>5__2e.Item1, this.<item>5__2e.Item2);
  2073. this.<>1__state = 2;
  2074. return true;
  2075. }
  2076. Label_0109:
  2077. if (this.<>7__wrap2f.MoveNext())
  2078. {
  2079. goto Label_007F;
  2080. }
  2081. this.<>m__Finally30();
  2082. Label_011F:
  2083. flag = false;
  2084. }
  2085. fault
  2086. {
  2087. this.System.IDisposable.Dispose();
  2088. }
  2089. return flag;
  2090. }
  2091. [DebuggerHidden]
  2092. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2093. {
  2094. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DistinctWithComparer>d__2c d__c;
  2095. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2096. {
  2097. this.<>1__state = 0;
  2098. d__c = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DistinctWithComparer>d__2c) this;
  2099. }
  2100. else
  2101. {
  2102. d__c = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<DistinctWithComparer>d__2c(0);
  2103. }
  2104. d__c.elementLocation = this.<>3__elementLocation;
  2105. d__c.functionName = this.<>3__functionName;
  2106. d__c.itemsOfType = this.<>3__itemsOfType;
  2107. d__c.arguments = this.<>3__arguments;
  2108. d__c.comparer = this.<>3__comparer;
  2109. return d__c;
  2110. }
  2111. [DebuggerHidden]
  2112. IEnumerator IEnumerable.GetEnumerator()
  2113. {
  2114. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2115. }
  2116. [DebuggerHidden]
  2117. void IEnumerator.Reset()
  2118. {
  2119. throw new NotSupportedException();
  2120. }
  2121. void IDisposable.Dispose()
  2122. {
  2123. switch (this.<>1__state)
  2124. {
  2125. case 1:
  2126. case 2:
  2127. try
  2128. {
  2129. }
  2130. finally
  2131. {
  2132. this.<>m__Finally30();
  2133. }
  2134. return;
  2135. }
  2136. }
  2137. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2138. {
  2139. [DebuggerHidden]
  2140. get
  2141. {
  2142. return this.<>2__current;
  2143. }
  2144. }
  2145. object IEnumerator.Current
  2146. {
  2147. [DebuggerHidden]
  2148. get
  2149. {
  2150. return this.<>2__current;
  2151. }
  2152. }
  2153. }
  2154. [CompilerGenerated]
  2155. private sealed class <ExecuteStringFunction>d__41 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2156. {
  2157. private int <>1__state;
  2158. private Tuple<string, S> <>2__current;
  2159. public string[] <>3__arguments;
  2160. public IElementLocation <>3__elementLocation;
  2161. public Expander<P, I> <>3__expander;
  2162. public string <>3__functionName;
  2163. public bool <>3__includeNullEntries;
  2164. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2165. public IEnumerator<Tuple<string, S>> <>7__wrap46;
  2166. private int <>l__initialThreadId;
  2167. public Expander<P, I>.Function<P> <function>5__43;
  2168. public string <include>5__45;
  2169. public Tuple<string, S> <item>5__42;
  2170. public object <result>5__44;
  2171. public string[] arguments;
  2172. public IElementLocation elementLocation;
  2173. public Expander<P, I> expander;
  2174. public string functionName;
  2175. public bool includeNullEntries;
  2176. public IEnumerable<Tuple<string, S>> itemsOfType;
  2177. [DebuggerHidden]
  2178. public <ExecuteStringFunction>d__41(int <>1__state)
  2179. {
  2180. this.<>1__state = <>1__state;
  2181. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2182. }
  2183. private void <>m__Finally47()
  2184. {
  2185. this.<>1__state = -1;
  2186. if (this.<>7__wrap46 != null)
  2187. {
  2188. this.<>7__wrap46.Dispose();
  2189. }
  2190. }
  2191. private bool MoveNext()
  2192. {
  2193. bool flag;
  2194. try
  2195. {
  2196. switch (this.<>1__state)
  2197. {
  2198. case 0:
  2199. this.<>1__state = -1;
  2200. this.<>7__wrap46 = this.itemsOfType.GetEnumerator();
  2201. this.<>1__state = 1;
  2202. goto Label_0152;
  2203. case 2:
  2204. this.<>1__state = 1;
  2205. goto Label_0152;
  2206. case 3:
  2207. this.<>1__state = 1;
  2208. goto Label_0152;
  2209. default:
  2210. goto Label_0168;
  2211. }
  2212. Label_0046:
  2213. this.<item>5__42 = this.<>7__wrap46.Current;
  2214. this.<function>5__43 = new Expander<P, I>.Function<P>(typeof(string), this.<item>5__42.Item1, this.<item>5__42.Item1, this.functionName, this.arguments, BindingFlags.InvokeMethod | BindingFlags.Public, string.Empty, this.expander.UsedUninitializedProperties);
  2215. this.<result>5__44 = this.<function>5__43.Execute(this.<item>5__42.Item1, this.expander.properties, ExpanderOptions.ExpandAll, this.elementLocation);
  2216. this.<include>5__45 = Expander<P, I>.PropertyExpander<P>.ConvertToString(this.<result>5__44);
  2217. if (this.<include>5__45.Length > 0)
  2218. {
  2219. this.<>2__current = new Tuple<string, S>(this.<include>5__45, this.<item>5__42.Item2);
  2220. this.<>1__state = 2;
  2221. return true;
  2222. }
  2223. if (this.includeNullEntries)
  2224. {
  2225. this.<>2__current = new Tuple<string, S>(null, this.<item>5__42.Item2);
  2226. this.<>1__state = 3;
  2227. return true;
  2228. }
  2229. Label_0152:
  2230. if (this.<>7__wrap46.MoveNext())
  2231. {
  2232. goto Label_0046;
  2233. }
  2234. this.<>m__Finally47();
  2235. Label_0168:
  2236. flag = false;
  2237. }
  2238. fault
  2239. {
  2240. this.System.IDisposable.Dispose();
  2241. }
  2242. return flag;
  2243. }
  2244. [DebuggerHidden]
  2245. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2246. {
  2247. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExecuteStringFunction>d__41 d__;
  2248. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2249. {
  2250. this.<>1__state = 0;
  2251. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExecuteStringFunction>d__41) this;
  2252. }
  2253. else
  2254. {
  2255. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExecuteStringFunction>d__41(0);
  2256. }
  2257. d__.expander = this.<>3__expander;
  2258. d__.elementLocation = this.<>3__elementLocation;
  2259. d__.includeNullEntries = this.<>3__includeNullEntries;
  2260. d__.functionName = this.<>3__functionName;
  2261. d__.itemsOfType = this.<>3__itemsOfType;
  2262. d__.arguments = this.<>3__arguments;
  2263. return d__;
  2264. }
  2265. [DebuggerHidden]
  2266. IEnumerator IEnumerable.GetEnumerator()
  2267. {
  2268. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2269. }
  2270. [DebuggerHidden]
  2271. void IEnumerator.Reset()
  2272. {
  2273. throw new NotSupportedException();
  2274. }
  2275. void IDisposable.Dispose()
  2276. {
  2277. switch (this.<>1__state)
  2278. {
  2279. case 1:
  2280. case 2:
  2281. case 3:
  2282. try
  2283. {
  2284. }
  2285. finally
  2286. {
  2287. this.<>m__Finally47();
  2288. }
  2289. return;
  2290. }
  2291. }
  2292. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2293. {
  2294. [DebuggerHidden]
  2295. get
  2296. {
  2297. return this.<>2__current;
  2298. }
  2299. }
  2300. object IEnumerator.Current
  2301. {
  2302. [DebuggerHidden]
  2303. get
  2304. {
  2305. return this.<>2__current;
  2306. }
  2307. }
  2308. }
  2309. [CompilerGenerated]
  2310. private sealed class <ExpandQuotedExpressionFunction>d__39 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2311. {
  2312. private int <>1__state;
  2313. private Tuple<string, S> <>2__current;
  2314. public string[] <>3__arguments;
  2315. public IElementLocation <>3__elementLocation;
  2316. public string <>3__functionName;
  2317. public bool <>3__includeNullEntries;
  2318. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2319. public IEnumerator<Tuple<string, S>> <>7__wrap3d;
  2320. private int <>l__initialThreadId;
  2321. public string <include>5__3c;
  2322. public Tuple<string, S> <item>5__3a;
  2323. public Expander<P, I>.ItemExpander.MetadataMatchEvaluator <matchEvaluator>5__3b;
  2324. public string[] arguments;
  2325. public IElementLocation elementLocation;
  2326. public string functionName;
  2327. public bool includeNullEntries;
  2328. public IEnumerable<Tuple<string, S>> itemsOfType;
  2329. [DebuggerHidden]
  2330. public <ExpandQuotedExpressionFunction>d__39(int <>1__state)
  2331. {
  2332. this.<>1__state = <>1__state;
  2333. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2334. }
  2335. private void <>m__Finally3e()
  2336. {
  2337. this.<>1__state = -1;
  2338. if (this.<>7__wrap3d != null)
  2339. {
  2340. this.<>7__wrap3d.Dispose();
  2341. }
  2342. }
  2343. private bool MoveNext()
  2344. {
  2345. bool flag;
  2346. try
  2347. {
  2348. switch (this.<>1__state)
  2349. {
  2350. case 0:
  2351. this.<>1__state = -1;
  2352. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments != null) && (this.arguments.Length == 1), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  2353. this.<>7__wrap3d = this.itemsOfType.GetEnumerator();
  2354. this.<>1__state = 1;
  2355. goto Label_0163;
  2356. case 2:
  2357. this.<>1__state = 1;
  2358. goto Label_0163;
  2359. case 3:
  2360. this.<>1__state = 1;
  2361. goto Label_0163;
  2362. default:
  2363. goto Label_0179;
  2364. }
  2365. Label_0072:
  2366. this.<item>5__3a = this.<>7__wrap3d.Current;
  2367. this.<include>5__3c = null;
  2368. if (this.<item>5__3a.Item1 != null)
  2369. {
  2370. this.<matchEvaluator>5__3b = new Expander<P, I>.ItemExpander.MetadataMatchEvaluator(this.<item>5__3a.Item1, this.<item>5__3a.Item2, this.elementLocation);
  2371. this.<include>5__3c = Expander<P, I>.RegularExpressions.ItemMetadataPattern.Replace(this.arguments[0], new MatchEvaluator(this.<matchEvaluator>5__3b.GetMetadataValueFromMatch));
  2372. }
  2373. if ((this.<include>5__3c != null) && (this.<include>5__3c.Length > 0))
  2374. {
  2375. this.<>2__current = new Tuple<string, S>(this.<include>5__3c, this.<item>5__3a.Item2);
  2376. this.<>1__state = 2;
  2377. return true;
  2378. }
  2379. if (this.includeNullEntries)
  2380. {
  2381. this.<>2__current = new Tuple<string, S>(null, this.<item>5__3a.Item2);
  2382. this.<>1__state = 3;
  2383. return true;
  2384. }
  2385. Label_0163:
  2386. if (this.<>7__wrap3d.MoveNext())
  2387. {
  2388. goto Label_0072;
  2389. }
  2390. this.<>m__Finally3e();
  2391. Label_0179:
  2392. flag = false;
  2393. }
  2394. fault
  2395. {
  2396. this.System.IDisposable.Dispose();
  2397. }
  2398. return flag;
  2399. }
  2400. [DebuggerHidden]
  2401. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2402. {
  2403. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExpandQuotedExpressionFunction>d__39 d__;
  2404. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2405. {
  2406. this.<>1__state = 0;
  2407. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExpandQuotedExpressionFunction>d__39) this;
  2408. }
  2409. else
  2410. {
  2411. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ExpandQuotedExpressionFunction>d__39(0);
  2412. }
  2413. d__.elementLocation = this.<>3__elementLocation;
  2414. d__.includeNullEntries = this.<>3__includeNullEntries;
  2415. d__.functionName = this.<>3__functionName;
  2416. d__.itemsOfType = this.<>3__itemsOfType;
  2417. d__.arguments = this.<>3__arguments;
  2418. return d__;
  2419. }
  2420. [DebuggerHidden]
  2421. IEnumerator IEnumerable.GetEnumerator()
  2422. {
  2423. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2424. }
  2425. [DebuggerHidden]
  2426. void IEnumerator.Reset()
  2427. {
  2428. throw new NotSupportedException();
  2429. }
  2430. void IDisposable.Dispose()
  2431. {
  2432. switch (this.<>1__state)
  2433. {
  2434. case 1:
  2435. case 2:
  2436. case 3:
  2437. try
  2438. {
  2439. }
  2440. finally
  2441. {
  2442. this.<>m__Finally3e();
  2443. }
  2444. return;
  2445. }
  2446. }
  2447. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2448. {
  2449. [DebuggerHidden]
  2450. get
  2451. {
  2452. return this.<>2__current;
  2453. }
  2454. }
  2455. object IEnumerator.Current
  2456. {
  2457. [DebuggerHidden]
  2458. get
  2459. {
  2460. return this.<>2__current;
  2461. }
  2462. }
  2463. }
  2464. [CompilerGenerated]
  2465. private sealed class <GetItemTupleEnumerator>d__a : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2466. {
  2467. private int <>1__state;
  2468. private Tuple<string, S> <>2__current;
  2469. public IEnumerable<S> <>3__itemsOfType;
  2470. public IEnumerator<S> <>7__wrapc;
  2471. private int <>l__initialThreadId;
  2472. public S <item>5__b;
  2473. public IEnumerable<S> itemsOfType;
  2474. [DebuggerHidden]
  2475. public <GetItemTupleEnumerator>d__a(int <>1__state)
  2476. {
  2477. this.<>1__state = <>1__state;
  2478. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2479. }
  2480. private void <>m__Finallyd()
  2481. {
  2482. this.<>1__state = -1;
  2483. if (this.<>7__wrapc != null)
  2484. {
  2485. this.<>7__wrapc.Dispose();
  2486. }
  2487. }
  2488. private bool MoveNext()
  2489. {
  2490. bool flag;
  2491. try
  2492. {
  2493. switch (this.<>1__state)
  2494. {
  2495. case 0:
  2496. this.<>1__state = -1;
  2497. this.<>7__wrapc = this.itemsOfType.GetEnumerator();
  2498. this.<>1__state = 1;
  2499. goto Label_0084;
  2500. case 2:
  2501. this.<>1__state = 1;
  2502. goto Label_0084;
  2503. default:
  2504. goto Label_0097;
  2505. }
  2506. Label_003C:
  2507. this.<item>5__b = this.<>7__wrapc.Current;
  2508. this.<>2__current = new Tuple<string, S>(this.<item>5__b.EvaluatedIncludeEscaped, this.<item>5__b);
  2509. this.<>1__state = 2;
  2510. return true;
  2511. Label_0084:
  2512. if (this.<>7__wrapc.MoveNext())
  2513. {
  2514. goto Label_003C;
  2515. }
  2516. this.<>m__Finallyd();
  2517. Label_0097:
  2518. flag = false;
  2519. }
  2520. fault
  2521. {
  2522. this.System.IDisposable.Dispose();
  2523. }
  2524. return flag;
  2525. }
  2526. [DebuggerHidden]
  2527. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2528. {
  2529. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<GetItemTupleEnumerator>d__a _a;
  2530. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2531. {
  2532. this.<>1__state = 0;
  2533. _a = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<GetItemTupleEnumerator>d__a) this;
  2534. }
  2535. else
  2536. {
  2537. _a = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<GetItemTupleEnumerator>d__a(0);
  2538. }
  2539. _a.itemsOfType = this.<>3__itemsOfType;
  2540. return _a;
  2541. }
  2542. [DebuggerHidden]
  2543. IEnumerator IEnumerable.GetEnumerator()
  2544. {
  2545. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2546. }
  2547. [DebuggerHidden]
  2548. void IEnumerator.Reset()
  2549. {
  2550. throw new NotSupportedException();
  2551. }
  2552. void IDisposable.Dispose()
  2553. {
  2554. switch (this.<>1__state)
  2555. {
  2556. case 1:
  2557. case 2:
  2558. try
  2559. {
  2560. }
  2561. finally
  2562. {
  2563. this.<>m__Finallyd();
  2564. }
  2565. return;
  2566. }
  2567. }
  2568. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2569. {
  2570. [DebuggerHidden]
  2571. get
  2572. {
  2573. return this.<>2__current;
  2574. }
  2575. }
  2576. object IEnumerator.Current
  2577. {
  2578. [DebuggerHidden]
  2579. get
  2580. {
  2581. return this.<>2__current;
  2582. }
  2583. }
  2584. }
  2585. [CompilerGenerated]
  2586. private sealed class <ItemSpecModifierFunction>d__10 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2587. {
  2588. private int <>1__state;
  2589. private Tuple<string, S> <>2__current;
  2590. public string[] <>3__arguments;
  2591. public IElementLocation <>3__elementLocation;
  2592. public string <>3__functionName;
  2593. public bool <>3__includeNullEntries;
  2594. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2595. public IEnumerator<Tuple<string, S>> <>7__wrap14;
  2596. private int <>l__initialThreadId;
  2597. public Tuple<string, S> <item>5__12;
  2598. public CopyOnWriteDictionary<string, string> <itemSpecModifierTable>5__11;
  2599. public string <result>5__13;
  2600. public string[] arguments;
  2601. public IElementLocation elementLocation;
  2602. public string functionName;
  2603. public bool includeNullEntries;
  2604. public IEnumerable<Tuple<string, S>> itemsOfType;
  2605. [DebuggerHidden]
  2606. public <ItemSpecModifierFunction>d__10(int <>1__state)
  2607. {
  2608. this.<>1__state = <>1__state;
  2609. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2610. }
  2611. private void <>m__Finally15()
  2612. {
  2613. this.<>1__state = -1;
  2614. if (this.<>7__wrap14 != null)
  2615. {
  2616. this.<>7__wrap14.Dispose();
  2617. }
  2618. }
  2619. private bool MoveNext()
  2620. {
  2621. bool flag;
  2622. try
  2623. {
  2624. switch (this.<>1__state)
  2625. {
  2626. case 0:
  2627. this.<>1__state = -1;
  2628. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments == null) || (this.arguments.Length == 0), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  2629. this.<itemSpecModifierTable>5__11 = new CopyOnWriteDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  2630. this.<>7__wrap14 = this.itemsOfType.GetEnumerator();
  2631. this.<>1__state = 1;
  2632. goto Label_019E;
  2633. case 3:
  2634. this.<>1__state = 1;
  2635. goto Label_019E;
  2636. case 4:
  2637. this.<>1__state = 1;
  2638. goto Label_019E;
  2639. default:
  2640. goto Label_01B4;
  2641. }
  2642. Label_0086:
  2643. this.<item>5__12 = this.<>7__wrap14.Current;
  2644. if (!string.IsNullOrEmpty(this.<item>5__12.Item1))
  2645. {
  2646. this.<result>5__13 = null;
  2647. try
  2648. {
  2649. string currentDirectory = this.<item>5__12.Item2.ProjectDirectory ?? Directory.GetCurrentDirectory();
  2650. this.<result>5__13 = FileUtilities.ItemSpecModifiers.GetItemSpecModifier(currentDirectory, this.<item>5__12.Item1, this.functionName, ref this.<itemSpecModifierTable>5__11);
  2651. }
  2652. catch (Exception exception)
  2653. {
  2654. if (ExceptionHandling.NotExpectedException(exception))
  2655. {
  2656. throw;
  2657. }
  2658. ProjectErrorUtilities.ThrowInvalidProject(this.elementLocation, "InvalidItemFunctionExpression", this.functionName, this.<item>5__12.Item1, exception.Message);
  2659. }
  2660. if (!string.IsNullOrEmpty(this.<result>5__13))
  2661. {
  2662. this.<>2__current = new Tuple<string, S>(this.<result>5__13, this.<item>5__12.Item2);
  2663. this.<>1__state = 3;
  2664. return true;
  2665. }
  2666. if (this.includeNullEntries)
  2667. {
  2668. this.<>2__current = new Tuple<string, S>(null, this.<item>5__12.Item2);
  2669. this.<>1__state = 4;
  2670. return true;
  2671. }
  2672. }
  2673. Label_019E:
  2674. if (this.<>7__wrap14.MoveNext())
  2675. {
  2676. goto Label_0086;
  2677. }
  2678. this.<>m__Finally15();
  2679. Label_01B4:
  2680. flag = false;
  2681. }
  2682. fault
  2683. {
  2684. this.System.IDisposable.Dispose();
  2685. }
  2686. return flag;
  2687. }
  2688. [DebuggerHidden]
  2689. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2690. {
  2691. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ItemSpecModifierFunction>d__10 d__;
  2692. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2693. {
  2694. this.<>1__state = 0;
  2695. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ItemSpecModifierFunction>d__10) this;
  2696. }
  2697. else
  2698. {
  2699. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<ItemSpecModifierFunction>d__10(0);
  2700. }
  2701. d__.elementLocation = this.<>3__elementLocation;
  2702. d__.includeNullEntries = this.<>3__includeNullEntries;
  2703. d__.functionName = this.<>3__functionName;
  2704. d__.itemsOfType = this.<>3__itemsOfType;
  2705. d__.arguments = this.<>3__arguments;
  2706. return d__;
  2707. }
  2708. [DebuggerHidden]
  2709. IEnumerator IEnumerable.GetEnumerator()
  2710. {
  2711. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2712. }
  2713. [DebuggerHidden]
  2714. void IEnumerator.Reset()
  2715. {
  2716. throw new NotSupportedException();
  2717. }
  2718. void IDisposable.Dispose()
  2719. {
  2720. switch (this.<>1__state)
  2721. {
  2722. case 1:
  2723. case 3:
  2724. case 4:
  2725. try
  2726. {
  2727. }
  2728. finally
  2729. {
  2730. this.<>m__Finally15();
  2731. }
  2732. break;
  2733. case 2:
  2734. break;
  2735. default:
  2736. return;
  2737. }
  2738. }
  2739. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2740. {
  2741. [DebuggerHidden]
  2742. get
  2743. {
  2744. return this.<>2__current;
  2745. }
  2746. }
  2747. object IEnumerator.Current
  2748. {
  2749. [DebuggerHidden]
  2750. get
  2751. {
  2752. return this.<>2__current;
  2753. }
  2754. }
  2755. }
  2756. [CompilerGenerated]
  2757. private sealed class <Metadata>d__20 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2758. {
  2759. private int <>1__state;
  2760. private Tuple<string, S> <>2__current;
  2761. public string[] <>3__arguments;
  2762. public IElementLocation <>3__elementLocation;
  2763. public string <>3__functionName;
  2764. public bool <>3__includeNullEntries;
  2765. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2766. public IEnumerator<Tuple<string, S>> <>7__wrap26;
  2767. public IEnumerator<string> <>7__wrap28;
  2768. private int <>l__initialThreadId;
  2769. public Tuple<string, S> <item>5__22;
  2770. public string <itemSpec>5__25;
  2771. public string <metadataName>5__21;
  2772. public string <metadataValue>5__23;
  2773. public IList<string> <splits>5__24;
  2774. public string[] arguments;
  2775. public IElementLocation elementLocation;
  2776. public string functionName;
  2777. public bool includeNullEntries;
  2778. public IEnumerable<Tuple<string, S>> itemsOfType;
  2779. [DebuggerHidden]
  2780. public <Metadata>d__20(int <>1__state)
  2781. {
  2782. this.<>1__state = <>1__state;
  2783. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2784. }
  2785. private void <>m__Finally27()
  2786. {
  2787. this.<>1__state = -1;
  2788. if (this.<>7__wrap26 != null)
  2789. {
  2790. this.<>7__wrap26.Dispose();
  2791. }
  2792. }
  2793. private void <>m__Finally29()
  2794. {
  2795. this.<>1__state = 1;
  2796. if (this.<>7__wrap28 != null)
  2797. {
  2798. this.<>7__wrap28.Dispose();
  2799. }
  2800. }
  2801. private bool MoveNext()
  2802. {
  2803. bool flag;
  2804. try
  2805. {
  2806. switch (this.<>1__state)
  2807. {
  2808. case 0:
  2809. this.<>1__state = -1;
  2810. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments != null) && (this.arguments.Length == 1), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  2811. this.<metadataName>5__21 = this.arguments[0];
  2812. this.<>7__wrap26 = this.itemsOfType.GetEnumerator();
  2813. this.<>1__state = 1;
  2814. goto Label_01F5;
  2815. case 3:
  2816. goto Label_0161;
  2817. case 4:
  2818. this.<>1__state = 1;
  2819. goto Label_01F5;
  2820. case 5:
  2821. this.<>1__state = 1;
  2822. goto Label_01F5;
  2823. default:
  2824. goto Label_020B;
  2825. }
  2826. Label_0088:
  2827. this.<item>5__22 = this.<>7__wrap26.Current;
  2828. if (this.<item>5__22.Item2 != null)
  2829. {
  2830. this.<metadataValue>5__23 = this.<item>5__22.Item2.GetMetadataValueEscaped(this.<metadataName>5__21);
  2831. if (!string.IsNullOrEmpty(this.<metadataValue>5__23))
  2832. {
  2833. if (Expander<P, I>.invariantCompareInfo.IndexOf(this.<metadataValue>5__23, ';') < 0)
  2834. {
  2835. this.<>2__current = new Tuple<string, S>(this.<metadataValue>5__23, this.<item>5__22.Item2);
  2836. this.<>1__state = 4;
  2837. return true;
  2838. }
  2839. this.<splits>5__24 = ExpressionShredder.SplitSemiColonSeparatedList(this.<metadataValue>5__23);
  2840. this.<>7__wrap28 = this.<splits>5__24.GetEnumerator();
  2841. this.<>1__state = 2;
  2842. while (this.<>7__wrap28.MoveNext())
  2843. {
  2844. this.<itemSpec>5__25 = this.<>7__wrap28.Current;
  2845. this.<>2__current = new Tuple<string, S>(this.<itemSpec>5__25, this.<item>5__22.Item2);
  2846. this.<>1__state = 3;
  2847. return true;
  2848. Label_0161:
  2849. this.<>1__state = 2;
  2850. }
  2851. this.<>m__Finally29();
  2852. }
  2853. else if ((this.<metadataValue>5__23 != string.Empty) && this.includeNullEntries)
  2854. {
  2855. this.<>2__current = new Tuple<string, S>(this.<metadataValue>5__23, this.<item>5__22.Item2);
  2856. this.<>1__state = 5;
  2857. return true;
  2858. }
  2859. }
  2860. Label_01F5:
  2861. if (this.<>7__wrap26.MoveNext())
  2862. {
  2863. goto Label_0088;
  2864. }
  2865. this.<>m__Finally27();
  2866. Label_020B:
  2867. flag = false;
  2868. }
  2869. fault
  2870. {
  2871. this.System.IDisposable.Dispose();
  2872. }
  2873. return flag;
  2874. }
  2875. [DebuggerHidden]
  2876. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  2877. {
  2878. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Metadata>d__20 d__;
  2879. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  2880. {
  2881. this.<>1__state = 0;
  2882. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Metadata>d__20) this;
  2883. }
  2884. else
  2885. {
  2886. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Metadata>d__20(0);
  2887. }
  2888. d__.elementLocation = this.<>3__elementLocation;
  2889. d__.includeNullEntries = this.<>3__includeNullEntries;
  2890. d__.functionName = this.<>3__functionName;
  2891. d__.itemsOfType = this.<>3__itemsOfType;
  2892. d__.arguments = this.<>3__arguments;
  2893. return d__;
  2894. }
  2895. [DebuggerHidden]
  2896. IEnumerator IEnumerable.GetEnumerator()
  2897. {
  2898. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  2899. }
  2900. [DebuggerHidden]
  2901. void IEnumerator.Reset()
  2902. {
  2903. throw new NotSupportedException();
  2904. }
  2905. void IDisposable.Dispose()
  2906. {
  2907. switch (this.<>1__state)
  2908. {
  2909. case 1:
  2910. case 2:
  2911. case 3:
  2912. case 4:
  2913. case 5:
  2914. try
  2915. {
  2916. switch (this.<>1__state)
  2917. {
  2918. case 2:
  2919. case 3:
  2920. try
  2921. {
  2922. }
  2923. finally
  2924. {
  2925. this.<>m__Finally29();
  2926. }
  2927. break;
  2928. }
  2929. }
  2930. finally
  2931. {
  2932. this.<>m__Finally27();
  2933. }
  2934. break;
  2935. default:
  2936. return;
  2937. }
  2938. }
  2939. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  2940. {
  2941. [DebuggerHidden]
  2942. get
  2943. {
  2944. return this.<>2__current;
  2945. }
  2946. }
  2947. object IEnumerator.Current
  2948. {
  2949. [DebuggerHidden]
  2950. get
  2951. {
  2952. return this.<>2__current;
  2953. }
  2954. }
  2955. }
  2956. [CompilerGenerated]
  2957. private sealed class <Reverse>d__33 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  2958. {
  2959. private int <>1__state;
  2960. private Tuple<string, S> <>2__current;
  2961. public string[] <>3__arguments;
  2962. public IElementLocation <>3__elementLocation;
  2963. public string <>3__functionName;
  2964. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  2965. public IEnumerator<Tuple<string, S>> <>7__wrap35;
  2966. private int <>l__initialThreadId;
  2967. public Tuple<string, S> <item>5__34;
  2968. public string[] arguments;
  2969. public IElementLocation elementLocation;
  2970. public string functionName;
  2971. public IEnumerable<Tuple<string, S>> itemsOfType;
  2972. [DebuggerHidden]
  2973. public <Reverse>d__33(int <>1__state)
  2974. {
  2975. this.<>1__state = <>1__state;
  2976. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  2977. }
  2978. private void <>m__Finally36()
  2979. {
  2980. this.<>1__state = -1;
  2981. if (this.<>7__wrap35 != null)
  2982. {
  2983. this.<>7__wrap35.Dispose();
  2984. }
  2985. }
  2986. private bool MoveNext()
  2987. {
  2988. bool flag;
  2989. try
  2990. {
  2991. switch (this.<>1__state)
  2992. {
  2993. case 0:
  2994. this.<>1__state = -1;
  2995. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments == null) || (this.arguments.Length == 0), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  2996. this.<>7__wrap35 = this.itemsOfType.Reverse<Tuple<string, S>>().GetEnumerator();
  2997. this.<>1__state = 1;
  2998. goto Label_00B4;
  2999. case 2:
  3000. this.<>1__state = 1;
  3001. goto Label_00B4;
  3002. default:
  3003. goto Label_00C7;
  3004. }
  3005. Label_0070:
  3006. this.<item>5__34 = this.<>7__wrap35.Current;
  3007. this.<>2__current = new Tuple<string, S>(this.<item>5__34.Item1, this.<item>5__34.Item2);
  3008. this.<>1__state = 2;
  3009. return true;
  3010. Label_00B4:
  3011. if (this.<>7__wrap35.MoveNext())
  3012. {
  3013. goto Label_0070;
  3014. }
  3015. this.<>m__Finally36();
  3016. Label_00C7:
  3017. flag = false;
  3018. }
  3019. fault
  3020. {
  3021. this.System.IDisposable.Dispose();
  3022. }
  3023. return flag;
  3024. }
  3025. [DebuggerHidden]
  3026. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  3027. {
  3028. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Reverse>d__33 d__;
  3029. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  3030. {
  3031. this.<>1__state = 0;
  3032. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Reverse>d__33) this;
  3033. }
  3034. else
  3035. {
  3036. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<Reverse>d__33(0);
  3037. }
  3038. d__.elementLocation = this.<>3__elementLocation;
  3039. d__.functionName = this.<>3__functionName;
  3040. d__.itemsOfType = this.<>3__itemsOfType;
  3041. d__.arguments = this.<>3__arguments;
  3042. return d__;
  3043. }
  3044. [DebuggerHidden]
  3045. IEnumerator IEnumerable.GetEnumerator()
  3046. {
  3047. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  3048. }
  3049. [DebuggerHidden]
  3050. void IEnumerator.Reset()
  3051. {
  3052. throw new NotSupportedException();
  3053. }
  3054. void IDisposable.Dispose()
  3055. {
  3056. switch (this.<>1__state)
  3057. {
  3058. case 1:
  3059. case 2:
  3060. try
  3061. {
  3062. }
  3063. finally
  3064. {
  3065. this.<>m__Finally36();
  3066. }
  3067. return;
  3068. }
  3069. }
  3070. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  3071. {
  3072. [DebuggerHidden]
  3073. get
  3074. {
  3075. return this.<>2__current;
  3076. }
  3077. }
  3078. object IEnumerator.Current
  3079. {
  3080. [DebuggerHidden]
  3081. get
  3082. {
  3083. return this.<>2__current;
  3084. }
  3085. }
  3086. }
  3087. [CompilerGenerated]
  3088. private sealed class <WithMetadataValue>d__50 : IEnumerable<Tuple<string, S>>, IEnumerable, IEnumerator<Tuple<string, S>>, IEnumerator, IDisposable
  3089. {
  3090. private int <>1__state;
  3091. private Tuple<string, S> <>2__current;
  3092. public string[] <>3__arguments;
  3093. public IElementLocation <>3__elementLocation;
  3094. public string <>3__functionName;
  3095. public IEnumerable<Tuple<string, S>> <>3__itemsOfType;
  3096. public IEnumerator<Tuple<string, S>> <>7__wrap55;
  3097. private int <>l__initialThreadId;
  3098. public Tuple<string, S> <item>5__53;
  3099. public string <metadataName>5__51;
  3100. public string <metadataValue>5__54;
  3101. public string <metadataValueToFind>5__52;
  3102. public string[] arguments;
  3103. public IElementLocation elementLocation;
  3104. public string functionName;
  3105. public IEnumerable<Tuple<string, S>> itemsOfType;
  3106. [DebuggerHidden]
  3107. public <WithMetadataValue>d__50(int <>1__state)
  3108. {
  3109. this.<>1__state = <>1__state;
  3110. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  3111. }
  3112. private void <>m__Finally56()
  3113. {
  3114. this.<>1__state = -1;
  3115. if (this.<>7__wrap55 != null)
  3116. {
  3117. this.<>7__wrap55.Dispose();
  3118. }
  3119. }
  3120. private bool MoveNext()
  3121. {
  3122. bool flag;
  3123. try
  3124. {
  3125. switch (this.<>1__state)
  3126. {
  3127. case 0:
  3128. this.<>1__state = -1;
  3129. ProjectErrorUtilities.VerifyThrowInvalidProject((this.arguments != null) && (this.arguments.Length == 2), this.elementLocation, "InvalidItemFunctionSyntax", this.functionName);
  3130. this.<metadataName>5__51 = this.arguments[0];
  3131. this.<metadataValueToFind>5__52 = this.arguments[1];
  3132. this.<>7__wrap55 = this.itemsOfType.GetEnumerator();
  3133. this.<>1__state = 1;
  3134. goto Label_010F;
  3135. case 2:
  3136. this.<>1__state = 1;
  3137. goto Label_010F;
  3138. default:
  3139. goto Label_0125;
  3140. }
  3141. Label_008A:
  3142. this.<item>5__53 = this.<>7__wrap55.Current;
  3143. this.<metadataValue>5__54 = this.<item>5__53.Item2.GetMetadataValue(this.<metadataName>5__51);
  3144. if ((this.<metadataValue>5__54 != null) && string.Equals(this.<metadataValue>5__54, this.<metadataValueToFind>5__52, StringComparison.OrdinalIgnoreCase))
  3145. {
  3146. this.<>2__current = new Tuple<string, S>(this.<item>5__53.Item1, this.<item>5__53.Item2);
  3147. this.<>1__state = 2;
  3148. return true;
  3149. }
  3150. Label_010F:
  3151. if (this.<>7__wrap55.MoveNext())
  3152. {
  3153. goto Label_008A;
  3154. }
  3155. this.<>m__Finally56();
  3156. Label_0125:
  3157. flag = false;
  3158. }
  3159. fault
  3160. {
  3161. this.System.IDisposable.Dispose();
  3162. }
  3163. return flag;
  3164. }
  3165. [DebuggerHidden]
  3166. IEnumerator<Tuple<string, S>> IEnumerable<Tuple<string, S>>.GetEnumerator()
  3167. {
  3168. Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<WithMetadataValue>d__50 d__;
  3169. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  3170. {
  3171. this.<>1__state = 0;
  3172. d__ = (Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<WithMetadataValue>d__50) this;
  3173. }
  3174. else
  3175. {
  3176. d__ = new Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.<WithMetadataValue>d__50(0);
  3177. }
  3178. d__.elementLocation = this.<>3__elementLocation;
  3179. d__.functionName = this.<>3__functionName;
  3180. d__.itemsOfType = this.<>3__itemsOfType;
  3181. d__.arguments = this.<>3__arguments;
  3182. return d__;
  3183. }
  3184. [DebuggerHidden]
  3185. IEnumerator IEnumerable.GetEnumerator()
  3186. {
  3187. return this.System.Collections.Generic.IEnumerable<System.Tuple<System.String,S>>.GetEnumerator();
  3188. }
  3189. [DebuggerHidden]
  3190. void IEnumerator.Reset()
  3191. {
  3192. throw new NotSupportedException();
  3193. }
  3194. void IDisposable.Dispose()
  3195. {
  3196. switch (this.<>1__state)
  3197. {
  3198. case 1:
  3199. case 2:
  3200. try
  3201. {
  3202. }
  3203. finally
  3204. {
  3205. this.<>m__Finally56();
  3206. }
  3207. return;
  3208. }
  3209. }
  3210. Tuple<string, S> IEnumerator<Tuple<string, S>>.Current
  3211. {
  3212. [DebuggerHidden]
  3213. get
  3214. {
  3215. return this.<>2__current;
  3216. }
  3217. }
  3218. object IEnumerator.Current
  3219. {
  3220. [DebuggerHidden]
  3221. get
  3222. {
  3223. return this.<>2__current;
  3224. }
  3225. }
  3226. }
  3227. public delegate IEnumerable<Tuple<string, S>> ItemTransformFunction(Expander<P, I> expander, IElementLocation elementLocation, bool includeNullEntries, string functionName, IEnumerable<Tuple<string, S>> itemsOfType, string[] arguments);
  3228. }
  3229. private class MetadataMatchEvaluator
  3230. {
  3231. private IElementLocation elementLocation;
  3232. private string itemSpec;
  3233. private IItem sourceOfMetadata;
  3234. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  3235. internal MetadataMatchEvaluator(string itemSpec, IItem sourceOfMetadata, IElementLocation elementLocation)
  3236. {
  3237. this.itemSpec = itemSpec;
  3238. this.sourceOfMetadata = sourceOfMetadata;
  3239. this.elementLocation = elementLocation;
  3240. }
  3241. internal string GetMetadataValueFromMatch(Match match)
  3242. {
  3243. string str = match.Groups["NAME"].Value;
  3244. ProjectErrorUtilities.VerifyThrowInvalidProject(match.Groups["ITEM_SPECIFICATION"].Length == 0, this.elementLocation, "QualifiedMetadataInTransformNotAllowed", match.Value, str);
  3245. CopyOnWriteDictionary<string, string> cachedModifiers = new CopyOnWriteDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  3246. string metadataValueEscaped = null;
  3247. try
  3248. {
  3249. if (FileUtilities.ItemSpecModifiers.IsDerivableItemSpecModifier(str))
  3250. {
  3251. string currentDirectory = this.sourceOfMetadata.ProjectDirectory ?? Directory.GetCurrentDirectory();
  3252. return FileUtilities.ItemSpecModifiers.GetItemSpecModifier(currentDirectory, this.itemSpec, str, ref cachedModifiers);
  3253. }
  3254. metadataValueEscaped = this.sourceOfMetadata.GetMetadataValueEscaped(str);
  3255. }
  3256. catch (InvalidOperationException exception)
  3257. {
  3258. ProjectErrorUtilities.ThrowInvalidProject(this.elementLocation, "CannotEvaluateItemMetadata", str, exception.Message);
  3259. }
  3260. return metadataValueEscaped;
  3261. }
  3262. }
  3263. internal class TransformFunction<S> where S: class, IItem
  3264. {
  3265. private string[] arguments;
  3266. private IElementLocation elementLocation;
  3267. private string functionName;
  3268. private Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.ItemTransformFunction transform;
  3269. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  3270. public TransformFunction(IElementLocation elementLocation, string functionName, Expander<P, I>.ItemExpander.IntrinsicItemFunctions<S>.ItemTransformFunction transform, string[] arguments)
  3271. {
  3272. this.elementLocation = elementLocation;
  3273. this.functionName = functionName;
  3274. this.transform = transform;
  3275. this.arguments = arguments;
  3276. }
  3277. public IEnumerable<Tuple<string, S>> Execute(Expander<P, I> expander, bool includeNullEntries, IEnumerable<Tuple<string, S>> itemsOfType)
  3278. {
  3279. return this.transform(expander, this.elementLocation, includeNullEntries, this.functionName, itemsOfType, this.arguments);
  3280. }
  3281. public string[] Arguments
  3282. {
  3283. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  3284. get
  3285. {
  3286. return this.arguments;
  3287. }
  3288. }
  3289. public IElementLocation ElementLocation
  3290. {
  3291. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  3292. get
  3293. {
  3294. return this.elementLocation;
  3295. }
  3296. }
  3297. }
  3298. }
  3299. private static class MetadataExpander
  3300. {
  3301. internal static string ExpandMetadataLeaveEscaped(string expression, IMetadataTable metadata, ExpanderOptions options)
  3302. {
  3303. if ((options & ExpanderOptions.ExpandMetadata) == ExpanderOptions.Invalid)
  3304. {
  3305. return expression;
  3306. }
  3307. if (expression.Length == 0)
  3308. {
  3309. return expression;
  3310. }
  3311. ErrorUtilities.VerifyThrow(metadata != null, "Cannot expand metadata without providing metadata");
  3312. if (Expander<P, I>.invariantCompareInfo.IndexOf(expression, "%(", CompareOptions.Ordinal) == -1)
  3313. {
  3314. return expression;
  3315. }
  3316. string a = null;
  3317. if (Expander<P, I>.invariantCompareInfo.IndexOf(expression, "@(", CompareOptions.Ordinal) == -1)
  3318. {
  3319. MetadataMatchEvaluator<P, I> evaluator = new MetadataMatchEvaluator<P, I>(metadata, options);
  3320. a = Expander<P, I>.RegularExpressions.ItemMetadataPattern.Replace(expression, new MatchEvaluator(evaluator.ExpandSingleMetadata));
  3321. }
  3322. else
  3323. {
  3324. List<ExpressionShredder.ItemExpressionCapture> referencedItemExpressions = ExpressionShredder.GetReferencedItemExpressions(expression);
  3325. if (((referencedItemExpressions != null) && (referencedItemExpressions.Count == 1)) && ((referencedItemExpressions[0].Value == expression) && (referencedItemExpressions[0].Separator == null)))
  3326. {
  3327. return expression;
  3328. }
  3329. StringBuilder candidate = new StringBuilder(expression.Length);
  3330. int startIndex = 0;
  3331. MetadataMatchEvaluator<P, I> evaluator2 = new MetadataMatchEvaluator<P, I>(metadata, options);
  3332. if (referencedItemExpressions != null)
  3333. {
  3334. for (int i = 0; i < referencedItemExpressions.Count; i++)
  3335. {
  3336. string str2 = referencedItemExpressions[i].Value;
  3337. string input = expression.Substring(startIndex, referencedItemExpressions[i].Index - startIndex);
  3338. string str4 = Expander<P, I>.RegularExpressions.NonTransformItemMetadataPattern.Replace(input, new MatchEvaluator(evaluator2.ExpandSingleMetadata));
  3339. candidate.Append(str4);
  3340. if (referencedItemExpressions[i].Separator != null)
  3341. {
  3342. str2 = Expander<P, I>.RegularExpressions.NonTransformItemMetadataPattern.Replace(referencedItemExpressions[i].Value, new MatchEvaluator(evaluator2.ExpandSingleMetadata), -1, referencedItemExpressions[i].SeparatorStart);
  3343. }
  3344. candidate.Append(str2);
  3345. startIndex = referencedItemExpressions[i].Index + referencedItemExpressions[i].Length;
  3346. }
  3347. }
  3348. if (startIndex < expression.Length)
  3349. {
  3350. string str5 = expression.Substring(startIndex);
  3351. string str6 = Expander<P, I>.RegularExpressions.NonTransformItemMetadataPattern.Replace(str5, new MatchEvaluator(evaluator2.ExpandSingleMetadata));
  3352. candidate.Append(str6);
  3353. }
  3354. a = OpportunisticIntern.StringBuilderToString(candidate);
  3355. }
  3356. if (string.Equals(a, expression, StringComparison.Ordinal))
  3357. {
  3358. a = expression;
  3359. }
  3360. return a;
  3361. }
  3362. private class MetadataMatchEvaluator
  3363. {
  3364. private IMetadataTable metadata;
  3365. private ExpanderOptions options;
  3366. internal MetadataMatchEvaluator(IMetadataTable metadata, ExpanderOptions options)
  3367. {
  3368. this.metadata = metadata;
  3369. this.options = options & ExpanderOptions.ExpandMetadata;
  3370. ErrorUtilities.VerifyThrow(options != ExpanderOptions.Invalid, "Must be expanding metadata of some kind");
  3371. }
  3372. internal string ExpandSingleMetadata(Match itemMetadataMatch)
  3373. {
  3374. ErrorUtilities.VerifyThrow(itemMetadataMatch.Success, "Need a valid item metadata.");
  3375. string name = itemMetadataMatch.Groups["NAME"].Value;
  3376. string itemType = null;
  3377. if (itemMetadataMatch.Groups["ITEM_SPECIFICATION"].Length > 0)
  3378. {
  3379. itemType = itemMetadataMatch.Groups["ITEM_TYPE"].Value;
  3380. }
  3381. string str3 = itemMetadataMatch.Value;
  3382. bool flag = FileUtilities.ItemSpecModifiers.IsItemSpecModifier(name);
  3383. if ((!flag || ((this.options & ExpanderOptions.ExpandBuiltInMetadata) == ExpanderOptions.Invalid)) && (flag || ((this.options & ExpanderOptions.ExpandCustomMetadata) == ExpanderOptions.Invalid)))
  3384. {
  3385. return str3;
  3386. }
  3387. return this.metadata.GetEscapedValue(itemType, name);
  3388. }
  3389. }
  3390. }
  3391. private static class PropertyExpander<T> where T: class, IProperty
  3392. {
  3393. internal static string ConvertToString(object valueToConvert)
  3394. {
  3395. if (valueToConvert == null)
  3396. {
  3397. return string.Empty;
  3398. }
  3399. if (valueToConvert.GetType() == typeof(string))
  3400. {
  3401. return (string) valueToConvert;
  3402. }
  3403. if (valueToConvert is IDictionary)
  3404. {
  3405. IDictionary dictionary = valueToConvert as IDictionary;
  3406. StringBuilder candidate = new StringBuilder();
  3407. foreach (DictionaryEntry entry in dictionary)
  3408. {
  3409. if (candidate.Length > 0)
  3410. {
  3411. candidate.Append(';');
  3412. }
  3413. candidate.Append(EscapingUtilities.Escape(Expander<P, I>.PropertyExpander<T>.ConvertToString(entry.Key)));
  3414. candidate.Append('=');
  3415. candidate.Append(EscapingUtilities.Escape(Expander<P, I>.PropertyExpander<T>.ConvertToString(entry.Value)));
  3416. }
  3417. return OpportunisticIntern.StringBuilderToString(candidate);
  3418. }
  3419. if (valueToConvert is IEnumerable)
  3420. {
  3421. StringBuilder builder2 = new StringBuilder();
  3422. IEnumerable enumerable = (IEnumerable) valueToConvert;
  3423. foreach (object obj2 in enumerable)
  3424. {
  3425. if (builder2.Length > 0)
  3426. {
  3427. builder2.Append(';');
  3428. }
  3429. builder2.Append(EscapingUtilities.Escape(Expander<P, I>.PropertyExpander<T>.ConvertToString(obj2)));
  3430. }
  3431. return OpportunisticIntern.StringBuilderToString(builder2);
  3432. }
  3433. return valueToConvert.ToString();
  3434. }
  3435. private static object ExpandMSBuildThisFileProperty(string propertyName, IElementLocation elementLocation)
  3436. {
  3437. if (!ReservedPropertyNames.IsReservedProperty(propertyName))
  3438. {
  3439. return string.Empty;
  3440. }
  3441. if (elementLocation.File.Length == 0)
  3442. {
  3443. return string.Empty;
  3444. }
  3445. string str = string.Empty;
  3446. if (string.Equals(propertyName, "MSBuildThisFile", StringComparison.OrdinalIgnoreCase))
  3447. {
  3448. return Path.GetFileName(elementLocation.File);
  3449. }
  3450. if (string.Equals(propertyName, "MSBuildThisFileName", StringComparison.OrdinalIgnoreCase))
  3451. {
  3452. return Path.GetFileNameWithoutExtension(elementLocation.File);
  3453. }
  3454. if (string.Equals(propertyName, "MSBuildThisFileFullPath", StringComparison.OrdinalIgnoreCase))
  3455. {
  3456. return FileUtilities.NormalizePath(elementLocation.File);
  3457. }
  3458. if (string.Equals(propertyName, "MSBuildThisFileExtension", StringComparison.OrdinalIgnoreCase))
  3459. {
  3460. return Path.GetExtension(elementLocation.File);
  3461. }
  3462. if (string.Equals(propertyName, "MSBuildThisFileDirectory", StringComparison.OrdinalIgnoreCase))
  3463. {
  3464. return FileUtilities.EnsureTrailingSlash(Path.GetDirectoryName(elementLocation.File));
  3465. }
  3466. if (string.Equals(propertyName, "MSBuildThisFileDirectoryNoRoot", StringComparison.OrdinalIgnoreCase))
  3467. {
  3468. string directoryName = Path.GetDirectoryName(elementLocation.File);
  3469. int length = Path.GetPathRoot(directoryName).Length;
  3470. str = FileUtilities.EnsureNoLeadingSlash(FileUtilities.EnsureTrailingSlash(directoryName.Substring(length)));
  3471. }
  3472. return str;
  3473. }
  3474. internal static string ExpandPropertiesLeaveEscaped(string expression, IPropertyProvider<T> properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
  3475. {
  3476. return Expander<P, I>.PropertyExpander<T>.ConvertToString(Expander<P, I>.PropertyExpander<T>.ExpandPropertiesLeaveTypedAndEscaped(expression, properties, options, elementLocation, usedUninitializedProperties));
  3477. }
  3478. internal static object ExpandPropertiesLeaveTypedAndEscaped(string expression, IPropertyProvider<T> properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
  3479. {
  3480. if (((options & ExpanderOptions.ExpandProperties) == ExpanderOptions.Invalid) || string.IsNullOrEmpty(expression))
  3481. {
  3482. return expression;
  3483. }
  3484. ErrorUtilities.VerifyThrow(properties != null, "Cannot expand properties without providing properties");
  3485. int startIndex = Expander<P, I>.invariantCompareInfo.IndexOf(expression, "$(", CompareOptions.Ordinal);
  3486. if (startIndex == -1)
  3487. {
  3488. return expression;
  3489. }
  3490. List<object> list = null;
  3491. object item = null;
  3492. int num3 = 0;
  3493. int length = expression.Length;
  3494. while (startIndex != -1)
  3495. {
  3496. if (item != null)
  3497. {
  3498. if (list == null)
  3499. {
  3500. list = new List<object>(4);
  3501. }
  3502. list.Add(item);
  3503. }
  3504. bool potentialPropertyFunction = false;
  3505. bool potentialRegistryFunction = false;
  3506. if ((startIndex - num3) > 0)
  3507. {
  3508. if (list == null)
  3509. {
  3510. list = new List<object>(4);
  3511. }
  3512. list.Add(expression.Substring(num3, startIndex - num3));
  3513. }
  3514. num3 = startIndex;
  3515. int num2 = Expander<P, I>.ScanForClosingParenthesis(expression, startIndex + 2, out potentialPropertyFunction, out potentialRegistryFunction);
  3516. if (num2 == -1)
  3517. {
  3518. item = expression.Substring(startIndex, expression.Length - startIndex);
  3519. num3 = expression.Length;
  3520. }
  3521. else
  3522. {
  3523. object propertyValue = null;
  3524. if ((startIndex + 2) == num2)
  3525. {
  3526. propertyValue = string.Empty;
  3527. }
  3528. else if ((((expression.Length - (startIndex + 2)) > 9) && potentialRegistryFunction) && (Expander<P, I>.invariantCompareInfo.IndexOf(expression, "Registry:", startIndex + 2, 9, CompareOptions.OrdinalIgnoreCase) == (startIndex + 2)))
  3529. {
  3530. propertyValue = Expander<P, I>.PropertyExpander<T>.ExpandRegistryValue(expression.Substring(startIndex + 2, (num2 - startIndex) - 2), elementLocation);
  3531. }
  3532. else if (((num2 - (startIndex + 2)) == 0x4d) && (Expander<P, I>.invariantCompareInfo.IndexOf(expression, @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\VSTSDB@VSTSDBDirectory", startIndex + 2, 0x4d, CompareOptions.OrdinalIgnoreCase) == (startIndex + 2)))
  3533. {
  3534. propertyValue = string.Empty;
  3535. }
  3536. else if (((num2 - (startIndex + 2)) == 0x13) && string.Equals(expression, "$(Solutions.VSVersion)", StringComparison.Ordinal))
  3537. {
  3538. propertyValue = string.Empty;
  3539. }
  3540. else if (potentialPropertyFunction)
  3541. {
  3542. propertyValue = Expander<P, I>.PropertyExpander<T>.ExpandPropertyBody(expression.Substring(startIndex + 2, (num2 - startIndex) - 2), propertyValue, properties, options, elementLocation, usedUninitializedProperties);
  3543. }
  3544. else
  3545. {
  3546. propertyValue = Expander<P, I>.PropertyExpander<T>.LookupProperty(properties, expression, startIndex + 2, num2 - 1, elementLocation, usedUninitializedProperties);
  3547. }
  3548. item = propertyValue;
  3549. num3 = num2 + 1;
  3550. }
  3551. startIndex = Expander<P, I>.invariantCompareInfo.IndexOf(expression, "$(", num3, CompareOptions.Ordinal);
  3552. }
  3553. if ((list == null) && (expression.Length == num3))
  3554. {
  3555. return item;
  3556. }
  3557. if (num3 == 0)
  3558. {
  3559. return expression;
  3560. }
  3561. StringBuilder candidate = new StringBuilder(expression.Length * 2);
  3562. if (list != null)
  3563. {
  3564. foreach (object obj4 in list)
  3565. {
  3566. candidate.Append(obj4.ToString());
  3567. }
  3568. }
  3569. if (item != null)
  3570. {
  3571. candidate.Append(item.ToString());
  3572. }
  3573. if ((expression.Length - num3) > 0)
  3574. {
  3575. candidate.Append(expression, num3, expression.Length - num3);
  3576. }
  3577. return OpportunisticIntern.StringBuilderToString(candidate);
  3578. }
  3579. internal static object ExpandPropertyBody(string propertyBody, object propertyValue, IPropertyProvider<T> properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
  3580. {
  3581. Expander<P, I>.Function<T> function = null;
  3582. string expressionRootName = propertyBody;
  3583. if (char.IsWhiteSpace(propertyBody[0]) || char.IsWhiteSpace(propertyBody[propertyBody.Length - 1]))
  3584. {
  3585. propertyBody = propertyBody.Trim();
  3586. }
  3587. if (!Expander<P, I>.IsValidPropertyName(propertyBody))
  3588. {
  3589. if (!propertyBody.Contains(".") && (propertyBody[0] != '['))
  3590. {
  3591. if ((propertyValue != null) || !propertyBody.Contains("["))
  3592. {
  3593. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", propertyBody, string.Empty);
  3594. return null;
  3595. }
  3596. int index = propertyBody.IndexOf('[');
  3597. int num2 = propertyBody.IndexOf(']');
  3598. if ((index >= 0) && (num2 >= 0))
  3599. {
  3600. propertyValue = Expander<P, I>.PropertyExpander<T>.LookupProperty(properties, propertyBody, 0, index - 1, elementLocation, usedUninitializedProperties);
  3601. propertyBody = propertyBody.Substring(index);
  3602. return Expander<P, I>.PropertyExpander<T>.ExpandPropertyBody(propertyBody, propertyValue, properties, options, elementLocation, usedUninitializedProperties);
  3603. }
  3604. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", propertyBody, AssemblyResources.GetString("InvalidFunctionPropertyExpressionDetailMismatchedSquareBrackets"));
  3605. }
  3606. else
  3607. {
  3608. if (Environment.GetEnvironmentVariable("MSBUILDDEBUGEXPANSION") == "1")
  3609. {
  3610. Console.WriteLine("Expanding: {0}", propertyBody);
  3611. }
  3612. function = Expander<P, I>.Function<T>.ExtractPropertyFunction(propertyBody, elementLocation, propertyValue, usedUninitializedProperties);
  3613. if (function == null)
  3614. {
  3615. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", propertyBody, string.Empty);
  3616. return null;
  3617. }
  3618. expressionRootName = function.ExpressionRootName;
  3619. }
  3620. }
  3621. if (!string.IsNullOrEmpty(expressionRootName))
  3622. {
  3623. propertyValue = Expander<P, I>.PropertyExpander<T>.LookupProperty(properties, expressionRootName, elementLocation, usedUninitializedProperties);
  3624. }
  3625. if (function != null)
  3626. {
  3627. propertyValue = function.Execute(propertyValue, properties, options, elementLocation);
  3628. }
  3629. return propertyValue;
  3630. }
  3631. private static string ExpandRegistryValue(string registryExpression, IElementLocation elementLocation)
  3632. {
  3633. string str = registryExpression.Substring(9);
  3634. int index = str.IndexOf('@');
  3635. int length = str.LastIndexOf('@');
  3636. ProjectErrorUtilities.VerifyThrowInvalidProject(index == length, elementLocation, "InvalidRegistryPropertyExpression", "$(" + registryExpression + ")", string.Empty);
  3637. string escapedString = ((length == -1) || (length == (str.Length - 1))) ? null : str.Substring(length + 1);
  3638. string str3 = (length != -1) ? str.Substring(0, length) : str;
  3639. string str4 = string.Empty;
  3640. if (str3 != null)
  3641. {
  3642. str3 = EscapingUtilities.UnescapeAll(str3);
  3643. if (escapedString != null)
  3644. {
  3645. escapedString = EscapingUtilities.UnescapeAll(escapedString);
  3646. }
  3647. try
  3648. {
  3649. object valueToConvert = Registry.GetValue(str3, escapedString, null);
  3650. if (valueToConvert != null)
  3651. {
  3652. return Expander<P, I>.PropertyExpander<T>.ConvertToString(valueToConvert);
  3653. }
  3654. str4 = string.Empty;
  3655. }
  3656. catch (Exception exception)
  3657. {
  3658. if (ExceptionHandling.NotExpectedRegistryException(exception))
  3659. {
  3660. throw;
  3661. }
  3662. ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidRegistryPropertyExpression", "$(" + registryExpression + ")", exception.Message);
  3663. }
  3664. }
  3665. return str4;
  3666. }
  3667. private static object LookupProperty(IPropertyProvider<T> properties, string propertyName, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
  3668. {
  3669. return Expander<P, I>.PropertyExpander<T>.LookupProperty(properties, propertyName, 0, propertyName.Length - 1, elementLocation, usedUninitializedProperties);
  3670. }
  3671. private static object LookupProperty(IPropertyProvider<T> properties, string propertyName, int startIndex, int endIndex, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
  3672. {
  3673. T local = properties.GetProperty(propertyName, startIndex, endIndex);
  3674. if ((local == null) && MSBuildNameIgnoreCaseComparer.Equals("MSBuild", propertyName, startIndex, 7))
  3675. {
  3676. if ((startIndex != 0) || (endIndex != propertyName.Length))
  3677. {
  3678. return Expander<P, I>.PropertyExpander<T>.ExpandMSBuildThisFileProperty(propertyName.Substring(startIndex, (endIndex - startIndex) + 1), elementLocation);
  3679. }
  3680. return Expander<P, I>.PropertyExpander<T>.ExpandMSBuildThisFileProperty(propertyName, elementLocation);
  3681. }
  3682. if (local == null)
  3683. {
  3684. if ((usedUninitializedProperties.Warn && (usedUninitializedProperties.CurrentlyEvaluatingPropertyElementName != null)) && !MSBuildNameIgnoreCaseComparer.Equals(usedUninitializedProperties.CurrentlyEvaluatingPropertyElementName, propertyName, startIndex, (endIndex - startIndex) + 1))
  3685. {
  3686. string key = propertyName.Substring(startIndex, (endIndex - startIndex) + 1);
  3687. if (!usedUninitializedProperties.Properties.ContainsKey(key))
  3688. {
  3689. usedUninitializedProperties.Properties.Add(key, elementLocation);
  3690. }
  3691. }
  3692. return string.Empty;
  3693. }
  3694. return local.EvaluatedValueEscaped;
  3695. }
  3696. }
  3697. private static class RegularExpressions
  3698. {
  3699. internal static readonly Regex ItemMetadataPattern;
  3700. private const string ItemMetadataSpecification = @"%\(\s* (?<ITEM_SPECIFICATION>(?<ITEM_TYPE>[A-Za-z_][A-Za-z_0-9\-]*)\s*\.\s*)? (?<NAME>[A-Za-z_][A-Za-z_0-9\-]*) \s*\)";
  3701. internal const string ItemSpecificationGroup = "ITEM_SPECIFICATION";
  3702. internal const string ItemTypeGroup = "ITEM_TYPE";
  3703. private const string ItemVectorWithTransformLHS = @"@\(\s*[A-Za-z_][A-Za-z_0-9\-]*\s*->\s*'[^']*";
  3704. private const string ItemVectorWithTransformRHS = @"[^']*'(\s*,\s*'[^']*')?\s*\)";
  3705. internal const string NameGroup = "NAME";
  3706. internal static readonly Regex NonTransformItemMetadataPattern;
  3707. static RegularExpressions()
  3708. {
  3709. Expander<P, I>.RegularExpressions.ItemMetadataPattern = new Regex(@"%\(\s* (?<ITEM_SPECIFICATION>(?<ITEM_TYPE>[A-Za-z_][A-Za-z_0-9\-]*)\s*\.\s*)? (?<NAME>[A-Za-z_][A-Za-z_0-9\-]*) \s*\)", RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
  3710. Expander<P, I>.RegularExpressions.NonTransformItemMetadataPattern = new Regex(@"((?<=@\(\s*[A-Za-z_][A-Za-z_0-9\-]*\s*->\s*'[^']*)%\(\s* (?<ITEM_SPECIFICATION>(?<ITEM_TYPE>[A-Za-z_][A-Za-z_0-9\-]*)\s*\.\s*)? (?<NAME>[A-Za-z_][A-Za-z_0-9\-]*) \s*\)(?![^']*'(\s*,\s*'[^']*')?\s*\))) | ((?<!@\(\s*[A-Za-z_][A-Za-z_0-9\-]*\s*->\s*'[^']*)%\(\s* (?<ITEM_SPECIFICATION>(?<ITEM_TYPE>[A-Za-z_][A-Za-z_0-9\-]*)\s*\.\s*)? (?<NAME>[A-Za-z_][A-Za-z_0-9\-]*) \s*\)(?=[^']*'(\s*,\s*'[^']*')?\s*\))) | ((?<!@\(\s*[A-Za-z_][A-Za-z_0-9\-]*\s*->\s*'[^']*)%\(\s* (?<ITEM_SPECIFICATION>(?<ITEM_TYPE>[A-Za-z_][A-Za-z_0-9\-]*)\s*\.\s*)? (?<NAME>[A-Za-z_][A-Za-z_0-9\-]*) \s*\)(?![^']*'(\s*,\s*'[^']*')?\s*\)))", RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
  3711. }
  3712. }
  3713. }
  3714. }