Skip to content

Commit 1a79792

Browse files
committed
+ ICanChooseToEscapeGeneration
1 parent 88f1b3f commit 1a79792

File tree

9 files changed

+271
-5
lines changed

9 files changed

+271
-5
lines changed

Generaid.Tests/Generaid.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
<EmbeddedResource Include="sample.proj" />
105105
</ItemGroup>
106106
<ItemGroup>
107+
<Content Include="HierarchyBuilderFacts.DoNotGenerate_Should_Work.approved.txt">
108+
<DependentUpon>HierarchyBuilderFacts.cs</DependentUpon>
109+
</Content>
107110
<Content Include="HierarchyBuilderFacts.Generate_Changes_Project_File.approved.txt">
108111
<DependentUpon>HierarchyBuilderFacts.cs</DependentUpon>
109112
</Content>
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{0FCE68B2-59F3-4D7D-9836-BF848ECCB36A}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Sample</RootNamespace>
12+
<AssemblyName>Sample.Tests</AssemblyName>
13+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<NuGetPackageImportStamp>09650d69</NuGetPackageImportStamp>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
36+
<HintPath>..\packages\ApprovalTests.3.0.11\lib\net40\ApprovalTests.dll</HintPath>
37+
<Private>True</Private>
38+
</Reference>
39+
<Reference Include="ApprovalUtilities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
40+
<HintPath>..\packages\ApprovalUtilities.3.0.11\lib\net45\ApprovalUtilities.dll</HintPath>
41+
<Private>True</Private>
42+
</Reference>
43+
<Reference Include="ApprovalUtilities.Net45, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
44+
<HintPath>..\packages\ApprovalUtilities.3.0.11\lib\net45\ApprovalUtilities.Net45.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
47+
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
49+
<Private>True</Private>
50+
</Reference>
51+
<Reference Include="EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
52+
<HintPath>..\packages\EntityFramework.Core.7.0.0-rc1-final\lib\net451\EntityFramework.Core.dll</HintPath>
53+
<Private>True</Private>
54+
</Reference>
55+
<Reference Include="EntityFramework.MicrosoftSqlServer, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
56+
<HintPath>..\packages\EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final\lib\net451\EntityFramework.MicrosoftSqlServer.dll</HintPath>
57+
<Private>True</Private>
58+
</Reference>
59+
<Reference Include="EntityFramework.Relational, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
60+
<HintPath>..\packages\EntityFramework.Relational.7.0.0-rc1-final\lib\net451\EntityFramework.Relational.dll</HintPath>
61+
<Private>True</Private>
62+
</Reference>
63+
<Reference Include="FluentAssertions, Version=4.3.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
64+
<HintPath>..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="FluentAssertions.Core, Version=4.3.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
68+
<HintPath>..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.Core.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
71+
<Reference Include="Microsoft.Extensions.Caching.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
72+
<HintPath>..\packages\Microsoft.Extensions.Caching.Abstractions.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Caching.Abstractions.dll</HintPath>
73+
<Private>True</Private>
74+
</Reference>
75+
<Reference Include="Microsoft.Extensions.Caching.Memory, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
76+
<HintPath>..\packages\Microsoft.Extensions.Caching.Memory.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Caching.Memory.dll</HintPath>
77+
<Private>True</Private>
78+
</Reference>
79+
<Reference Include="Microsoft.Extensions.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
80+
<HintPath>..\packages\Microsoft.Extensions.Configuration.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Configuration.dll</HintPath>
81+
<Private>True</Private>
82+
</Reference>
83+
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
84+
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
85+
<Private>True</Private>
86+
</Reference>
87+
<Reference Include="Microsoft.Extensions.Configuration.Binder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
88+
<HintPath>..\packages\Microsoft.Extensions.Configuration.Binder.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
89+
<Private>True</Private>
90+
</Reference>
91+
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
92+
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.DependencyInjection.dll</HintPath>
93+
<Private>True</Private>
94+
</Reference>
95+
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
96+
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
97+
<Private>True</Private>
98+
</Reference>
99+
<Reference Include="Microsoft.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
100+
<HintPath>..\packages\Microsoft.Extensions.Logging.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Logging.dll</HintPath>
101+
<Private>True</Private>
102+
</Reference>
103+
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
104+
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
105+
<Private>True</Private>
106+
</Reference>
107+
<Reference Include="Microsoft.Extensions.OptionsModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
108+
<HintPath>..\packages\Microsoft.Extensions.OptionsModel.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.OptionsModel.dll</HintPath>
109+
<Private>True</Private>
110+
</Reference>
111+
<Reference Include="Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
112+
<HintPath>..\packages\Microsoft.Extensions.Primitives.1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Primitives.dll</HintPath>
113+
<Private>True</Private>
114+
</Reference>
115+
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
116+
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
117+
<Private>True</Private>
118+
</Reference>
119+
<Reference Include="Remotion.Linq, Version=2.0.0.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
120+
<HintPath>..\packages\Remotion.Linq.2.0.1\lib\net45\Remotion.Linq.dll</HintPath>
121+
<Private>True</Private>
122+
</Reference>
123+
<Reference Include="System" />
124+
<Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
125+
<HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
126+
<Private>True</Private>
127+
</Reference>
128+
<Reference Include="System.ComponentModel.DataAnnotations" />
129+
<Reference Include="System.Core" />
130+
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
131+
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.0.0-beta-23516\lib\portable-net45+win8+wp8+wpa81\System.Diagnostics.DiagnosticSource.dll</HintPath>
132+
<Private>True</Private>
133+
</Reference>
134+
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
135+
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
136+
<Private>True</Private>
137+
</Reference>
138+
<Reference Include="System.Transactions" />
139+
<Reference Include="System.Xml.Linq" />
140+
<Reference Include="System.Data.DataSetExtensions" />
141+
<Reference Include="Microsoft.CSharp" />
142+
<Reference Include="System.Data" />
143+
<Reference Include="System.Xml" />
144+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
145+
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
146+
<Private>True</Private>
147+
</Reference>
148+
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
149+
<HintPath>..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll</HintPath>
150+
<Private>True</Private>
151+
</Reference>
152+
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
153+
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll</HintPath>
154+
<Private>True</Private>
155+
</Reference>
156+
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
157+
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
158+
<Private>True</Private>
159+
</Reference>
160+
</ItemGroup>
161+
<ItemGroup>
162+
<Compile Include="ChangeSetFacts.cs" />
163+
<Compile Include="CsProjExtensions.cs" />
164+
<Compile Include="HierarchyFacts.cs" />
165+
<Compile Include="Properties\AssemblyInfo.cs" />
166+
<Compile Include="XDocFacts.cs" />
167+
<Compile Include="Generated\root">
168+
<DependentUpon></DependentUpon>
169+
</Compile>
170+
<Compile Include="Generated\John">
171+
<DependentUpon></DependentUpon>
172+
</Compile>
173+
<Compile Include="Generated\Marry">
174+
<DependentUpon></DependentUpon>
175+
</Compile>
176+
<Compile Include="Generated\companies\Apple">
177+
<DependentUpon></DependentUpon>
178+
</Compile>
179+
<Compile Include="Generated\Alice">
180+
<DependentUpon></DependentUpon>
181+
</Compile>
182+
<Compile Include="Generated\Bob">
183+
<DependentUpon></DependentUpon>
184+
</Compile>
185+
</ItemGroup>
186+
<ItemGroup>
187+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
188+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
189+
</ItemGroup>
190+
<ItemGroup>
191+
<ProjectReference Include="..\Generator\Generator.csproj">
192+
<Project>{7B227385-B83D-4E16-868E-E307967D0EE4}</Project>
193+
<Name>Generator</Name>
194+
</ProjectReference>
195+
<ProjectReference Include="..\Sample\Sample.csproj">
196+
<Project>{D3B9E4FF-68D0-4898-A85E-281950135DFB}</Project>
197+
<Name>Sample</Name>
198+
</ProjectReference>
199+
</ItemGroup>
200+
<ItemGroup>
201+
<None Include="packages.config" />
202+
</ItemGroup>
203+
<ItemGroup>
204+
<Content Include="HierarchyFacts.Build.approved.txt">
205+
<DependentUpon>HierarchyFacts.cs</DependentUpon>
206+
</Content>
207+
<Content Include="HierarchyFacts.Expand2.approved.txt">
208+
<DependentUpon>HierarchyFacts.cs</DependentUpon>
209+
</Content>
210+
</ItemGroup>
211+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
212+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
213+
<PropertyGroup>
214+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
215+
</PropertyGroup>
216+
<Error Condition="!Exists('..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props'))" />
217+
</Target>
218+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
219+
Other similar extension points exist, see Microsoft.Common.targets.
220+
<Target Name="BeforeBuild">
221+
</Target>
222+
<Target Name="AfterBuild">
223+
</Target>
224+
-->
225+
</Project>

Generaid.Tests/HierarchyBuilderFacts.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,27 @@ public void Generate_Should_Respect_Subfolders()
122122
@"c:\proj\Generated\Alice",
123123
@"c:\proj\Generated\Bob");
124124
}
125+
[Fact]
126+
public void DoNotGenerate_Should_Work()
127+
{
128+
_model.Companies[0].DoNotGenerate = true;
129+
foreach (var company in _model.Companies)
130+
company.NeedSubfolder = true;
131+
132+
_hierarchyBuilder.Generate();
133+
_fs.AllFiles
134+
.Except(new[] { @"c:\proj\sample.proj" })
135+
.Should().BeEquivalentTo(
136+
@"c:\proj\Generated\companies\Apple",
137+
@"c:\proj\Generated\root",
138+
@"c:\proj\Generated\John",
139+
@"c:\proj\Generated\Marry",
140+
@"c:\proj\Generated\Alice",
141+
@"c:\proj\Generated\Bob");
142+
143+
Approvals.Verify(_fs.File.
144+
ReadAllText("c:/proj/sample.proj"));
145+
}
146+
125147
}
126148
}

Generaid.Tests/Model.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ public sealed class ModelGenerator : ITransformer
77
public string Name => "root";
88
public string TransformText() => "root";
99
}
10-
public class CompanyGenerator : ITransformer
10+
public class CompanyGenerator : ITransformer, ICanChooseToEscapeGeneration
1111
{
1212
public CompanyGenerator(Company company) { _company = company; }
1313
private readonly Company _company;
1414
public string Name =>
1515
(_company.NeedSubfolder ? @"companies\" : "")
1616
+ _company.Name;
1717
public string TransformText() => _company.Name;
18+
public bool DoNotGenerate => _company.DoNotGenerate;
1819
}
1920
public class EmployeeGenerator : ITransformer
2021
{
@@ -37,6 +38,7 @@ public sealed class Company
3738
public string Name { get; }
3839
public Employee[] Employees { get; }
3940
public bool NeedSubfolder { get; set; }
41+
public bool DoNotGenerate { get; set; }
4042

4143
public Company(string name, params Employee[] employees)
4244
{

Generaid/Generaid.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<Reference Include="System.Xml" />
5151
</ItemGroup>
5252
<ItemGroup>
53+
<Compile Include="ICanChooseToEscapeGeneration.cs" />
5354
<Compile Include="Internal\CmpNode.cs" />
5455
<Compile Include="Internal\CsProjExtensions.cs" />
5556
<Compile Include="Internal\GenHierarchy.cs" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Generaid
2+
{
3+
/// <summary>Implement to escape generating file</summary>
4+
public interface ICanChooseToEscapeGeneration
5+
{
6+
/// <summary>Return to -true- if you wish the file to never be generated</summary>
7+
bool DoNotGenerate { get; }
8+
}
9+
}

Generaid/ITransformer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public interface ITransformer
88
/// <summary>T4 should generate this automatically for you</summary>
99
string TransformText();
1010
}
11+
1112
}

Generaid/Internal/GenHierarchy.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.IO.Abstractions;
54
using System.Linq;
65
using System.Xml.Linq;
@@ -61,9 +60,11 @@ public void Generate()
6160
var doc = ReadProj();
6261
var nodes = GetAllNodes().ToList();
6362
foreach (var node in nodes)
64-
node.Generate(projectDir);
65-
var set = new HashSet<CmpNode>(nodes.Select(
66-
n => new CmpNode(n.FullName, n.DependentUpon)));
63+
if (node.DoGenerate)
64+
node.Generate(projectDir);
65+
var set = new HashSet<CmpNode>(nodes
66+
.Where(n => n.DoGenerate)
67+
.Select(n => new CmpNode(n.FullName, n.DependentUpon)));
6768
if (doc.Update(GeneratedDirName, set))
6869
SaveProj(doc);
6970
}

Generaid/Internal/GenNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public IEnumerable<GenNode> GetDescendantsAndSelf()
5959
foreach (var d in child.GetDescendantsAndSelf())
6060
yield return d;
6161
}
62+
public bool DoGenerate =>
63+
(Transformer as ICanChooseToEscapeGeneration)?.DoNotGenerate != true;
6264

6365
public void Generate(string projectRoot)
6466
{

0 commit comments

Comments
 (0)