Skip to content

Commit fca5ecd

Browse files
committed
Support common base class for model base classes.
1 parent e57c1ce commit fca5ecd

7 files changed

+50
-3
lines changed

src/Core/Models/GraphElementModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public IGraphElementModel ConfigureMetadata(MemberInfo member, Func<MemberMetada
138138
public IImmutableSet<MemberInfo> Members { get; }
139139

140140

141-
private bool IsWithinModel(MemberInfo memberInfo) => memberInfo.DeclaringType is { } declaringType && IsWithinModel(declaringType);
141+
private bool IsWithinModel(MemberInfo memberInfo) => memberInfo.DeclaringType is { } declaringType && (IsWithinModel(declaringType) || declaringType.IsAssignableFrom(typeof(TBaseType)));
142142

143143
private bool IsWithinModel(Type type) => typeof(TBaseType).IsAssignableFrom(type) && _assemblies.Contains(type.Assembly);
144144

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace ExRam.Gremlinq.Core.Tests
2+
{
3+
public sealed class ConcreteVertexElement : VertexElement
4+
{
5+
6+
}
7+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace ExRam.Gremlinq.Core.Tests
2+
{
3+
public abstract class EdgeElement : Element
4+
{
5+
6+
}
7+
}

test/Core.Tests/Elements/Element.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace ExRam.Gremlinq.Core.Tests
2+
{
3+
public abstract class Element
4+
{
5+
public string? Id { get; set; }
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace ExRam.Gremlinq.Core.Tests
2+
{
3+
public abstract class VertexElement : Element
4+
{
5+
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
Key: {
3+
RawKey: {
4+
EnumName: T,
5+
EnumValue: id
6+
}
7+
},
8+
SerializationBehaviour: IgnoreAlways
9+
}

test/Core.Tests/GraphModelTest.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace ExRam.Gremlinq.Core.Tests
88
{
99
public class GraphModelTest : VerifyBase
1010
{
11-
12-
1311
public GraphModelTest() : base()
1412
{
1513

@@ -368,5 +366,17 @@ public async Task AddAssemblies()
368366
.Should()
369367
.NotBeNull();
370368
}
369+
370+
[Fact]
371+
public async Task Configuration_IgnoreAlways_Id_when_inheriting_from_Element()
372+
{
373+
await Verify(GraphModel
374+
.FromBaseTypes<VertexElement, EdgeElement>()
375+
.ConfigureVertices(pm => pm
376+
.ConfigureElement<VertexElement>(conf => conf
377+
.IgnoreAlways(p => p.Id)))
378+
.VerticesModel
379+
.GetMetadata(typeof(VertexElement).GetProperty(nameof(VertexElement.Id))!));
380+
}
371381
}
372382
}

0 commit comments

Comments
 (0)