Skip to content

Commit 4b8e7a2

Browse files
committed
Add most support for type hierarchies.
1 parent 084a9a1 commit 4b8e7a2

File tree

4 files changed

+210
-52
lines changed

4 files changed

+210
-52
lines changed

ImmutableObjectGraph.CodeGeneration.Tests/CodeGenTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public async Task OneScalarFieldWithBuilder_BuilderHasToImmutableMethod()
9595
Assert.True(result.DeclaredMethods.Any(m => m.ContainingType?.Name == "Builder" && m.Name == "ToImmutable" && m.Parameters.Length == 0 && !m.IsStatic));
9696
}
9797

98+
[Fact]
99+
public async Task ClassDerivesFromAnotherWithFields_DerivedCreateParametersIncludeBaseFields()
100+
{
101+
var result = await this.GenerateFromStreamAsync("ClassDerivesFromAnotherWithFields");
102+
Assert.True(result.DeclaredMethods.Any(m => m.ContainingType?.Name == "Fruit" && m.Name == "Create" && m.Parameters.Length == 1));
103+
Assert.True(result.DeclaredMethods.Any(m => m.ContainingType?.Name == "Apple" && m.Name == "Create" && m.Parameters.Length == 2));
104+
}
105+
98106
protected async Task<GenerationResult> GenerateFromStreamAsync(string testName)
99107
{
100108
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(this.GetType().Namespace + ".TestSources." + testName + ".cs"))

ImmutableObjectGraph.CodeGeneration.Tests/ImmutableObjectGraph.CodeGeneration.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<ItemGroup>
109109
<Compile Include="CodeGenTests.cs" />
110110
<Compile Include="Properties\AssemblyInfo.cs" />
111+
<EmbeddedResource Include="TestSources\ClassDerivesFromAnotherWithFields.cs" />
111112
<EmbeddedResource Include="TestSources\OneScalarFieldWithBuilder.cs" />
112113
<EmbeddedResource Include="TestSources\OneScalarField.cs" />
113114
<EmbeddedResource Include="TestSources\FamilyPersonWatch.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[ImmutableObjectGraph.CodeGeneration.GenerateImmutable]
2+
partial class Fruit
3+
{
4+
readonly int seeds;
5+
}
6+
7+
[ImmutableObjectGraph.CodeGeneration.GenerateImmutable]
8+
partial class Apple : Fruit
9+
{
10+
readonly string color;
11+
}

0 commit comments

Comments
 (0)