PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Microsoft.Build/Microsoft.Build/Microsoft/Build/Evaluation/ProjectProperty.cs

#
C# | 216 lines | 196 code | 20 blank | 0 comment | 27 complexity | a1af206170bfc273cebe5596f8ff02bb MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.Evaluation
  2. {
  3. using Microsoft.Build.Collections;
  4. using Microsoft.Build.Construction;
  5. using Microsoft.Build.Internal;
  6. using Microsoft.Build.Shared;
  7. using System;
  8. using System.Diagnostics;
  9. using System.Runtime;
  10. [DebuggerDisplay("{name}={EvaluatedValue} [{xml.Value}]")]
  11. public class ProjectProperty : IValued, IProperty, IKeyed, IEquatable<ProjectProperty>
  12. {
  13. private string evaluatedValueEscaped;
  14. private readonly string name;
  15. private ProjectProperty predecessor;
  16. private readonly Microsoft.Build.Evaluation.Project project;
  17. private readonly ProjectPropertyElement xml;
  18. internal ProjectProperty(Microsoft.Build.Evaluation.Project project, ProjectPropertyElement xml, string evaluatedValueEscaped, ProjectProperty predecessor)
  19. {
  20. ErrorUtilities.VerifyThrowArgumentNull(xml, "xml");
  21. ErrorUtilities.VerifyThrowArgumentNull(evaluatedValueEscaped, "evaluatedValueEscaped");
  22. ErrorUtilities.VerifyThrowInvalidOperation(!this.ProjectHasMatchingGlobalProperty(project, xml.Name), "OM_GlobalProperty", xml.Name);
  23. this.project = project;
  24. this.xml = xml;
  25. this.name = xml.Name;
  26. this.evaluatedValueEscaped = evaluatedValueEscaped;
  27. this.predecessor = predecessor;
  28. }
  29. internal ProjectProperty(Microsoft.Build.Evaluation.Project project, string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved)
  30. {
  31. ErrorUtilities.VerifyThrowArgumentLength(name, "name");
  32. ErrorUtilities.VerifyThrowArgumentNull(evaluatedValueEscaped, "evaluatedValueEscaped");
  33. ErrorUtilities.VerifyThrowInvalidOperation(isGlobalProperty || !this.ProjectHasMatchingGlobalProperty(project, name), "OM_GlobalProperty", name);
  34. ErrorUtilities.VerifyThrowArgument(XMakeElements.IllegalItemPropertyNames[name] == null, "OM_ReservedName", name);
  35. ErrorUtilities.VerifyThrowArgument(mayBeReserved || !ReservedPropertyNames.IsReservedProperty(name), "OM_ReservedName", name);
  36. this.project = project;
  37. this.xml = null;
  38. this.name = name;
  39. this.evaluatedValueEscaped = evaluatedValueEscaped;
  40. }
  41. private bool ProjectHasMatchingGlobalProperty(Microsoft.Build.Evaluation.Project project, string propertyName)
  42. {
  43. ProjectProperty property = project.GetProperty(propertyName);
  44. return ((property != null) && property.IsGlobalProperty);
  45. }
  46. bool IEquatable<ProjectProperty>.Equals(ProjectProperty other)
  47. {
  48. if (object.ReferenceEquals(this, other))
  49. {
  50. return true;
  51. }
  52. if (other == null)
  53. {
  54. return false;
  55. }
  56. return ((((this.project == other.project) && (this.xml == other.xml)) && (this.evaluatedValueEscaped == other.evaluatedValueEscaped)) && (this.name == other.name));
  57. }
  58. internal void UpdateEvaluatedValue(string evaluatedValueEscaped)
  59. {
  60. this.evaluatedValueEscaped = evaluatedValueEscaped;
  61. }
  62. public string EvaluatedValue
  63. {
  64. [DebuggerStepThrough]
  65. get
  66. {
  67. return EscapingUtilities.UnescapeAll(this.evaluatedValueEscaped);
  68. }
  69. }
  70. public bool IsEnvironmentProperty
  71. {
  72. get
  73. {
  74. return ((!this.IsGlobalProperty && !this.IsReservedProperty) && (this.xml == null));
  75. }
  76. }
  77. public bool IsGlobalProperty
  78. {
  79. [DebuggerStepThrough]
  80. get
  81. {
  82. return this.project.GlobalProperties.ContainsKey(this.name);
  83. }
  84. }
  85. public bool IsImported
  86. {
  87. get
  88. {
  89. if ((this.IsEnvironmentProperty || this.IsGlobalProperty) || this.IsReservedProperty)
  90. {
  91. return false;
  92. }
  93. return !object.ReferenceEquals(this.xml.ContainingProject, this.project.Xml);
  94. }
  95. }
  96. public bool IsReservedProperty
  97. {
  98. [DebuggerStepThrough]
  99. get
  100. {
  101. return ReservedPropertyNames.IsReservedProperty(this.name);
  102. }
  103. }
  104. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  105. string IKeyed.Key
  106. {
  107. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  108. get
  109. {
  110. return this.Name;
  111. }
  112. }
  113. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  114. string IValued.EscapedValue
  115. {
  116. [DebuggerStepThrough]
  117. get
  118. {
  119. return this.evaluatedValueEscaped;
  120. }
  121. }
  122. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  123. string IProperty.EvaluatedValueEscaped
  124. {
  125. [DebuggerStepThrough]
  126. get
  127. {
  128. return this.evaluatedValueEscaped;
  129. }
  130. }
  131. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  132. public string Name
  133. {
  134. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  135. get
  136. {
  137. return this.name;
  138. }
  139. }
  140. public ProjectProperty Predecessor
  141. {
  142. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  143. get
  144. {
  145. return this.predecessor;
  146. }
  147. }
  148. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  149. public Microsoft.Build.Evaluation.Project Project
  150. {
  151. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  152. get
  153. {
  154. return this.project;
  155. }
  156. }
  157. public string UnevaluatedValue
  158. {
  159. [DebuggerStepThrough]
  160. get
  161. {
  162. if (this.xml != null)
  163. {
  164. return this.xml.Value;
  165. }
  166. return this.evaluatedValueEscaped;
  167. }
  168. set
  169. {
  170. ErrorUtilities.VerifyThrowInvalidOperation(!this.IsReservedProperty, "OM_ReservedName", this.name);
  171. ErrorUtilities.VerifyThrowInvalidOperation(!this.IsGlobalProperty, "OM_GlobalProperty", this.name);
  172. if (this.IsEnvironmentProperty)
  173. {
  174. this.evaluatedValueEscaped = value;
  175. this.project.Xml.AddProperty(this.name, value);
  176. }
  177. else
  178. {
  179. this.Project.VerifyThrowInvalidOperationNotImported(this.xml.ContainingProject);
  180. ErrorUtilities.VerifyThrowInvalidOperation((this.xml.Parent != null) && (this.xml.Parent.Parent != null), "OM_ObjectIsNoLongerActive");
  181. this.xml.Value = value;
  182. this.evaluatedValueEscaped = this.project.ExpandPropertyValueBestEffortLeaveEscaped(value, this.xml.Location);
  183. }
  184. }
  185. }
  186. [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  187. public ProjectPropertyElement Xml
  188. {
  189. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  190. get
  191. {
  192. return this.xml;
  193. }
  194. }
  195. }
  196. }