From e36fb95c50ce0cd0ab9621afe668332895712c2e Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Mon, 2 Oct 2017 23:24:00 +0200 Subject: Added mono module --- .../GodotSharpTools/Project/ProjectExtensions.cs | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs (limited to 'modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs') diff --git a/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs b/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs new file mode 100644 index 000000000..6a9773153 --- /dev/null +++ b/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.Build.Construction; + +namespace GodotSharpTools.Project +{ + public static class ProjectExtensions + { + public static bool HasItem(this ProjectRootElement root, string itemType, string include) + { + string includeNormalized = include.NormalizePath(); + + foreach (var itemGroup in root.ItemGroups) + { + if (itemGroup.Condition.Length != 0) + continue; + + foreach (var item in itemGroup.Items) + { + if (item.ItemType == itemType) + { + if (item.Include.NormalizePath() == includeNormalized) + return true; + } + } + } + + return false; + } + + public static void AddItemChecked(this ProjectRootElement root, string itemType, string include) + { + if (!root.HasItem(itemType, include)) + { + root.AddItem(itemType, include); + } + } + + public static Guid GetGuid(this ProjectRootElement root) + { + foreach (var property in root.Properties) + { + if (property.Name == "ProjectGuid") + return Guid.Parse(property.Value); + } + + return Guid.Empty; + } + } +} -- cgit v1.2.3-70-g09d2