diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2015-12-16 18:49:38 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2016-01-12 14:45:59 +0300 |
commit | 2e372684ff34864b7ce95e619f7c6b64eae01ec1 (patch) | |
tree | 6e93d336494026a8ed1412da624d63eec02ce1a0 /main | |
parent | e889cef57d1c73b3bd711675dd4048aeab9da720 (diff) |
[Core] Added new optional argument to MSBuildProperty.SetValue
This argument allows specifying a custom type handler, to be used when
comparing property values. Also added a new type for comparing Guids.
Diffstat (limited to 'main')
8 files changed, 44 insertions, 18 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMetadataProperty.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMetadataProperty.cs index 23bbbb74bc..8f9c627d19 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMetadataProperty.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMetadataProperty.cs @@ -50,7 +50,7 @@ namespace MonoDevelop.Projects.MSBuild bool TryGetPathValue (out FilePath value, bool relativeToProject = true, FilePath relativeToPath = default(FilePath)); - void SetValue (string value, bool preserveCase = false, bool mergeToMainGroup = false); + void SetValue (string value, bool preserveCase = false, bool mergeToMainGroup = false, MSBuildValueType valueType = null); void SetValue (FilePath value, bool relativeToProject = true, FilePath relativeToPath = default(FilePath), bool mergeToMainGroup = false); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProperty.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProperty.cs index f3c0cc8d0a..3587efa803 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProperty.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProperty.cs @@ -220,20 +220,25 @@ namespace MonoDevelop.Projects.MSBuild return new MergedProperty (Name, preserverCase, HasDefaultValue); } - public void SetValue (string value, bool preserveCase = false, bool mergeToMainGroup = false) + public void SetValue (string value, bool preserveCase = false, bool mergeToMainGroup = false, MSBuildValueType valueType = null) { AssertCanModify (); + + // If no value type is specified, use the default + if (valueType == null) + valueType = preserveCase ? MSBuildValueType.DefaultPreserveCase : MSBuildValueType.Default; + MergeToMainGroup = mergeToMainGroup; this.preserverCase = preserveCase; - valueType = preserveCase ? MSBuildValueType.Default : MSBuildValueType.DefaultPreserveCase; + this.valueType = valueType; if (value == null) value = String.Empty; - if (preserveCase) { + if (valueType != MSBuildValueType.Default) { var current = GetPropertyValue (); if (current != null) { - if (current.Equals (value, preserveCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture)) + if (valueType.Equals (current, value)) return; } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroup.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroup.cs index 624b94a372..53d73e16ae 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroup.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroup.cs @@ -278,17 +278,23 @@ namespace MonoDevelop.Projects.MSBuild return AddProperty (name, condition); } - public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null) + public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null, MSBuildValueType valueType = null) { AssertCanModify (); + + // If no value type is specified, use the default + if (valueType == null) + valueType = preserveExistingCase ? MSBuildValueType.DefaultPreserveCase : MSBuildValueType.Default; + if (value == null && defaultValue == "") value = ""; + var prop = GetProperty (name, condition); var isDefault = value == defaultValue; if (isDefault && !mergeToMainGroup) { // if the value is default, only remove the property if it was not already the default // to avoid unnecessary project file churn - if (prop != null && string.Equals (defaultValue ?? "", prop.Value, preserveExistingCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) + if (prop != null && valueType.Equals (defaultValue ?? "", prop.Value)) return; if (!IgnoreDefaultValues) { if (prop != null) @@ -298,7 +304,7 @@ namespace MonoDevelop.Projects.MSBuild } if (prop == null) prop = AddProperty (name, condition); - prop.SetValue (value, preserveExistingCase, mergeToMainGroup); + prop.SetValue (value, preserveExistingCase, mergeToMainGroup, valueType); prop.HasDefaultValue = isDefault; } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupMerged.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupMerged.cs index 291f3f9a6a..bfdba318fc 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupMerged.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupMerged.cs @@ -105,9 +105,9 @@ namespace MonoDevelop.Projects.MSBuild groups [0].SetValue (name, value, preserveExistingCase:preserveExistingCase); } - public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null) + public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null, MSBuildValueType valueType = null) { - GetGroupForProperty (name).SetValue (name, value, defaultValue, preserveExistingCase, mergeToMainGroup, condition); + GetGroupForProperty (name).SetValue (name, value, defaultValue, preserveExistingCase, mergeToMainGroup, condition, valueType); } public void SetValue (string name, FilePath value, FilePath defaultValue = default(FilePath), bool relativeToProject = true, FilePath relativeToPath = default(FilePath), bool mergeToMainGroup = false, string condition = null) diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildValueType.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildValueType.cs index d64ef6a9a4..ca56d70dcb 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildValueType.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildValueType.cs @@ -27,13 +27,14 @@ using System; namespace MonoDevelop.Projects.MSBuild { - class MSBuildValueType + public class MSBuildValueType { public static readonly MSBuildValueType Default = new MSBuildValueType (); public static readonly MSBuildValueType DefaultPreserveCase = new PreserveCaseValueType (); public static readonly MSBuildValueType Path = new PathValueType (); public static readonly MSBuildValueType Boolean = new PreserveCaseValueType (); - public static readonly MSBuildValueType UnresolvedPath = new PathValueType (); + public static readonly MSBuildValueType Guid = new GuidValueType (); + internal static readonly MSBuildValueType UnresolvedPath = new PathValueType (); public virtual bool Equals (string ob1, string ob2) { @@ -60,5 +61,15 @@ namespace MonoDevelop.Projects.MSBuild return ob1.Equals (ob2, StringComparison.OrdinalIgnoreCase); } } + + class GuidValueType: MSBuildValueType + { + public override bool Equals (string ob1, string ob2) + { + ob1 = ob1.Trim ('{', '}'); + ob2 = ob2.Trim ('{', '}'); + return ob1.Equals (ob2, StringComparison.OrdinalIgnoreCase); + } + } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IPropertySet.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IPropertySet.cs index b86d8715e1..a5a96bb7d6 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IPropertySet.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IPropertySet.cs @@ -48,7 +48,7 @@ namespace MonoDevelop.Projects IMetadataProperty GetProperty (string name); IEnumerable<IMetadataProperty> GetProperties (); - void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null); + void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, bool mergeToMainGroup = false, string condition = null, MSBuildValueType valueType = null); void SetValue (string name, FilePath value, FilePath defaultValue = default(FilePath), bool relativeToProject = true, FilePath relativeToPath = default(FilePath), bool mergeToMainGroup = false, string condition = null); void SetValue (string name, object value, object defaultValue = null, bool mergeToMainGroup = false, string condition = null); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs index f8829ba397..6b27bedcb9 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs @@ -2402,7 +2402,7 @@ namespace MonoDevelop.Projects globalGroup.SetValue ("ProductVersion", productVersion); globalGroup.SetValue ("SchemaVersion", schemaVersion); - globalGroup.SetValue ("ProjectGuid", ItemId); + globalGroup.SetValue ("ProjectGuid", ItemId, valueType:MSBuildValueType.Guid); if (flavorGuids.Length > 0) { string gg = string.Join (";", flavorGuids); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectItemMetadata.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectItemMetadata.cs index 2a4f870b2b..0305e81c38 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectItemMetadata.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectItemMetadata.cs @@ -222,13 +222,17 @@ namespace MonoDevelop.Projects return null; } - void IPropertySet.SetValue (string name, string value, string defaultValue, bool preserveExistingCase, bool mergeToMainGroup, string condition) + void IPropertySet.SetValue (string name, string value, string defaultValue, bool preserveExistingCase, bool mergeToMainGroup, string condition, MSBuildValueType valueType) { - SetValue (name, value, defaultValue, preserveExistingCase); + SetValue (name, value, defaultValue, preserveExistingCase, valueType); } - public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false) + public void SetValue (string name, string value, string defaultValue = null, bool preserveExistingCase = false, MSBuildValueType valueType = null) { + // If no value type is specified, use the default + if (valueType == null) + valueType = preserveExistingCase ? MSBuildValueType.DefaultPreserveCase : MSBuildValueType.Default; + if (value == null && defaultValue == "") value = ""; var prop = (MSBuildProperty) GetProperty (name); @@ -236,7 +240,7 @@ namespace MonoDevelop.Projects if (isDefault) { // if the value is default, only remove the property if it was not already the default // to avoid unnecessary project file churn - if (prop != null && (defaultValue == null || !string.Equals (defaultValue, prop.Value, preserveExistingCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))) + if (prop != null && (defaultValue == null || !valueType.Equals (defaultValue, prop.Value))) RemoveProperty (prop); return; } |