/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
- namespace Microsoft.Build.Evaluation
- {
- using Microsoft.Build.Collections;
- using Microsoft.Build.Construction;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using System;
- using System.Diagnostics;
- using System.Runtime;
-
- [DebuggerDisplay("{name}={EvaluatedValue} [{xml.Value}]")]
- public class ProjectProperty : IValued, IProperty, IKeyed, IEquatable<ProjectProperty>
- {
- private string evaluatedValueEscaped;
- private readonly string name;
- private ProjectProperty predecessor;
- private readonly Microsoft.Build.Evaluation.Project project;
- private readonly ProjectPropertyElement xml;
-
- internal ProjectProperty(Microsoft.Build.Evaluation.Project project, ProjectPropertyElement xml, string evaluatedValueEscaped, ProjectProperty predecessor)
- {
- ErrorUtilities.VerifyThrowArgumentNull(xml, "xml");
- ErrorUtilities.VerifyThrowArgumentNull(evaluatedValueEscaped, "evaluatedValueEscaped");
- ErrorUtilities.VerifyThrowInvalidOperation(!this.ProjectHasMatchingGlobalProperty(project, xml.Name), "OM_GlobalProperty", xml.Name);
- this.project = project;
- this.xml = xml;
- this.name = xml.Name;
- this.evaluatedValueEscaped = evaluatedValueEscaped;
- this.predecessor = predecessor;
- }
-
- internal ProjectProperty(Microsoft.Build.Evaluation.Project project, string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved)
- {
- ErrorUtilities.VerifyThrowArgumentLength(name, "name");
- ErrorUtilities.VerifyThrowArgumentNull(evaluatedValueEscaped, "evaluatedValueEscaped");
- ErrorUtilities.VerifyThrowInvalidOperation(isGlobalProperty || !this.ProjectHasMatchingGlobalProperty(project, name), "OM_GlobalProperty", name);
- ErrorUtilities.VerifyThrowArgument(XMakeElements.IllegalItemPropertyNames[name] == null, "OM_ReservedName", name);
- ErrorUtilities.VerifyThrowArgument(mayBeReserved || !ReservedPropertyNames.IsReservedProperty(name), "OM_ReservedName", name);
- this.project = project;
- this.xml = null;
- this.name = name;
- this.evaluatedValueEscaped = evaluatedValueEscaped;
- }
-
- private bool ProjectHasMatchingGlobalProperty(Microsoft.Build.Evaluation.Project project, string propertyName)
- {
- ProjectProperty property = project.GetProperty(propertyName);
- return ((property != null) && property.IsGlobalProperty);
- }
-
- bool IEquatable<ProjectProperty>.Equals(ProjectProperty other)
- {
- if (object.ReferenceEquals(this, other))
- {
- return true;
- }
- if (other == null)
- {
- return false;
- }
- return ((((this.project == other.project) && (this.xml == other.xml)) && (this.evaluatedValueEscaped == other.evaluatedValueEscaped)) && (this.name == other.name));
- }
-
- internal void UpdateEvaluatedValue(string evaluatedValueEscaped)
- {
- this.evaluatedValueEscaped = evaluatedValueEscaped;
- }
-
- public string EvaluatedValue
- {
- [DebuggerStepThrough]
- get
- {
- return EscapingUtilities.UnescapeAll(this.evaluatedValueEscaped);
- }
- }
-
- public bool IsEnvironmentProperty
- {
- get
- {
- return ((!this.IsGlobalProperty && !this.IsReservedProperty) && (this.xml == null));
- }
- }
-
- public bool IsGlobalProperty
- {
- [DebuggerStepThrough]
- get
- {
- return this.project.GlobalProperties.ContainsKey(this.name);
- }
- }
-
- public bool IsImported
- {
- get
- {
- if ((this.IsEnvironmentProperty || this.IsGlobalProperty) || this.IsReservedProperty)
- {
- return false;
- }
- return !object.ReferenceEquals(this.xml.ContainingProject, this.project.Xml);
- }
- }
-
- public bool IsReservedProperty
- {
- [DebuggerStepThrough]
- get
- {
- return ReservedPropertyNames.IsReservedProperty(this.name);
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- string IKeyed.Key
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.Name;
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- string IValued.EscapedValue
- {
- [DebuggerStepThrough]
- get
- {
- return this.evaluatedValueEscaped;
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- string IProperty.EvaluatedValueEscaped
- {
- [DebuggerStepThrough]
- get
- {
- return this.evaluatedValueEscaped;
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public string Name
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.name;
- }
- }
-
- public ProjectProperty Predecessor
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.predecessor;
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public Microsoft.Build.Evaluation.Project Project
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.project;
- }
- }
-
- public string UnevaluatedValue
- {
- [DebuggerStepThrough]
- get
- {
- if (this.xml != null)
- {
- return this.xml.Value;
- }
- return this.evaluatedValueEscaped;
- }
- set
- {
- ErrorUtilities.VerifyThrowInvalidOperation(!this.IsReservedProperty, "OM_ReservedName", this.name);
- ErrorUtilities.VerifyThrowInvalidOperation(!this.IsGlobalProperty, "OM_GlobalProperty", this.name);
- if (this.IsEnvironmentProperty)
- {
- this.evaluatedValueEscaped = value;
- this.project.Xml.AddProperty(this.name, value);
- }
- else
- {
- this.Project.VerifyThrowInvalidOperationNotImported(this.xml.ContainingProject);
- ErrorUtilities.VerifyThrowInvalidOperation((this.xml.Parent != null) && (this.xml.Parent.Parent != null), "OM_ObjectIsNoLongerActive");
- this.xml.Value = value;
- this.evaluatedValueEscaped = this.project.ExpandPropertyValueBestEffortLeaveEscaped(value, this.xml.Location);
- }
- }
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public ProjectPropertyElement Xml
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.xml;
- }
- }
- }
- }
-