//
using System;
+using System.Linq;
using Microsoft.Build.Construction;
namespace Microsoft.Build.Evaluation
internal abstract class BaseProjectProperty : ProjectProperty
{
- public BaseProjectProperty (Project project, PropertyType propertyType)
+ public BaseProjectProperty (Project project, PropertyType propertyType, string name)
: base (project)
{
property_type = propertyType;
+ this.name = name;
+ predecessor = project.Properties.FirstOrDefault (p => p.Name == name);
+ if (predecessor != null)
+ project.RemoveProperty (predecessor);
}
PropertyType property_type;
+ readonly string name;
+ public override string Name {
+ get { return name; }
+ }
+
public override bool IsEnvironmentProperty {
get { return property_type == PropertyType.Environment; }
}
public override bool IsReservedProperty {
get { return property_type == PropertyType.Reserved; }
}
+ readonly ProjectProperty predecessor;
public override ProjectProperty Predecessor {
- get {
- throw new NotImplementedException ();
- }
+ get { return predecessor; }
}
}
internal class XmlProjectProperty : BaseProjectProperty
{
public XmlProjectProperty (Project project, ProjectPropertyElement xml, PropertyType propertyType)
- : base (project, propertyType)
+ : base (project, propertyType, xml.Name)
{
this.xml = xml;
}
ProjectPropertyElement xml;
- public override string Name {
- get { return xml.Name; }
- }
public override string UnevaluatedValue {
get { return xml.Value; }
set { xml.Value = value; }
internal class EnvironmentProjectProperty : BaseProjectProperty
{
public EnvironmentProjectProperty (Project project, string name, string value)
- : base (project, PropertyType.Environment)
+ : base (project, PropertyType.Environment, name)
{
- this.name = name;
this.value = value;
}
- readonly string name, value;
+ readonly string value;
- public override string Name {
- get { return name; }
- }
public override string UnevaluatedValue {
get { return value; }
set { throw new InvalidOperationException (string.Format ("You cannot change value of environment property '{0}'.", Name)); }
internal class GlobalProjectProperty : BaseProjectProperty
{
public GlobalProjectProperty (Project project, string name, string value)
- : base (project, PropertyType.Global)
+ : base (project, PropertyType.Global, name)
{
- this.name = name;
this.value = value;
}
- readonly string name, value;
+ readonly string value;
- public override string Name {
- get { return name; }
- }
public override string UnevaluatedValue {
get { return value; }
set { throw new InvalidOperationException (string.Format ("You cannot change value of global property '{0}'.", Name)); }
<PropertyGroup>
<Foo>Bar</Foo>
<Item/>
+ <X>1</X>
+ <X>2</X>
+ <PATH>overriden</PATH>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
Assert.AreEqual ("Bar", prop.UnevaluatedValue, "#2");
prop.UnevaluatedValue = "x";
Assert.AreEqual ("x", pe.Value, "#3");
+
+ prop = proj.Properties.First (p => p.Name == "X");
+ Assert.AreEqual ("2", prop.UnevaluatedValue, "#4");
+ Assert.IsNotNull (prop.Predecessor, "#5");
+ Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6");
+
+ // environment property could also be Predecessor (and removed...maybe.
+ // I could reproduce only NRE = .NET bug with environment property so far.)
+ prop = proj.Properties.First (p => p.Name == "PATH");
+ Assert.AreEqual ("2", prop.UnevaluatedValue, "#7");
+ Assert.IsNotNull (prop.Predecessor, "#5");
+ Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6");
}
[Test]