From 1919a2edc2cd4d85120062fec3b4b5f55cf6773e Mon Sep 17 00:00:00 2001 From: Lluis Sanchez Date: Wed, 18 Jan 2017 12:41:21 +0100 Subject: Allow referencing properties inside manifests Inside an XML manifest it is now possible to reference a property defined in the add-in header using the syntax $(Name). For example, $(Version) will be replaced by the version number of the add-in. --- .../Mono.Addins.Description/AddinDescription.cs | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Mono.Addins/Mono.Addins.Description/AddinDescription.cs') diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 724204f..bc0e508 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -698,6 +698,28 @@ namespace Mono.Addins.Description if (val != null) flags = (AddinFlags) Enum.Parse (typeof(AddinFlags), val); } + + bool TryGetVariableValue (string name, out string value) + { + if (variables != null && variables.TryGetValue (name, out value)) + return true; + + switch (name) { + case "Id": value = id; return true; + case "Namespace": value = ns; return true; + case "Version": value = version; return true; + case "CompatVersion": value = compatVersion; return true; + case "DefaultEnabled": value = defaultEnabled.ToString (); return true; + case "IsRoot": value = isroot.ToString (); return true; + case "Flags": value = flags.ToString (); return true; + } + if (properties != null && properties.HasProperty (name)) { + value = properties.GetPropertyValue (name); + return true; + } + value = null; + return false; + } /// /// Saves the add-in description. @@ -1002,7 +1024,7 @@ namespace Mono.Addins.Description internal string ParseString (string input) { - if (input == null || input.Length < 4 || variables == null || variables.Count == 0) + if (input == null || input.Length < 4) return input; int i = input.IndexOf ("$("); @@ -1029,7 +1051,7 @@ namespace Mono.Addins.Description string tag = input.Substring (start, i - start); string tagValue; - if (variables.TryGetValue (tag, out tagValue)) + if (TryGetVariableValue (tag, out tagValue)) result.Append (tagValue); else { result.Append ('$'); -- cgit v1.2.3