Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 8c26cc9

Browse files
committed
[Ide] Implement HasReference support in FileTemplate.
1 parent f671515 commit 8c26cc9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

main/src/core/MonoDevelop.Ide/ExtensionModel/Templates.addin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
</Extension>
9393

9494
<Extension path = "/MonoDevelop/Ide/FileTemplateConditionTypes">
95+
<FileTemplateConditionType name = "HasReference" class = "MonoDevelop.Ide.Templates.HasReferenceFileTemplateCondition"/>
9596
<FileTemplateConditionType name = "ClrVersion" class = "MonoDevelop.Ide.Templates.ClrVersionFileTemplateCondition"/>
9697
<FileTemplateConditionType name = "PartialTypeSupport" class = "MonoDevelop.Ide.Templates.PartialTypeFileTemplateCondition"/>
9798
<FileTemplateConditionType name = "ParentProject" class = "MonoDevelop.Ide.Templates.ParentProjectFileTemplateCondition"/>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// HasReferenceFileTemplateCondition.cs
3+
//
4+
// Author:
5+
// therzok <[email protected]>
6+
//
7+
// Copyright (c) 2017 (c) Marius Ungureanu
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using System.Linq;
28+
using System.Xml;
29+
using MonoDevelop.Projects;
30+
31+
namespace MonoDevelop.Ide.Templates
32+
{
33+
public class HasReferenceFileTemplateCondition : FileTemplateCondition
34+
{
35+
string reference;
36+
public override void Load (XmlElement element)
37+
{
38+
reference = element.GetAttribute ("Assembly");
39+
if (string.IsNullOrWhiteSpace (reference))
40+
throw new InvalidOperationException ("Invalid value for Assembly condition in template.");
41+
}
42+
43+
public override bool ShouldEnableFor (Project proj, string projectPath)
44+
{
45+
var dnp = proj as DotNetProject;
46+
if (dnp != null) {
47+
return dnp.References.Where (x => x.ReferenceType != ReferenceType.Project).Any (x => {
48+
var trimmed = x.StoredReference.TrimStart ();
49+
int commaIndex = trimmed.IndexOf (',');
50+
return trimmed.IndexOf (reference, 0, commaIndex, StringComparison.Ordinal) == 0;
51+
});
52+
}
53+
return false;
54+
}
55+
}
56+
}

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9369,6 +9369,7 @@
93699369
<Compile Include="MonoDevelop.Ide.Templates\MicrosoftTemplateEngineSolutionTemplate.cs" />
93709370
<Compile Include="MonoDevelop.Ide.Templates\MicrosoftTemplateEngineProcessedTemplateResult.cs" />
93719371
<Compile Include="MonoDevelop.Ide.Codons\TemplateExtensionNode.cs" />
9372+
<Compile Include="MonoDevelop.Ide.Templates\HasReferenceFileTemplateCondition.cs" />
93729373
</ItemGroup>
93739374
<ItemGroup>
93749375
<None Include="Makefile.am" />

0 commit comments

Comments
 (0)