Skip to content

Commit 1f2eb78

Browse files
committed
feat: include public fields in POCOs
1 parent c9288ab commit 1f2eb78

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Diffract/Differ.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ module DifferImpl =
124124
|> e.Accept
125125
addNonRecursiveToCache differ cache
126126
| Shape.Poco (:? ShapePoco<'T> as p) ->
127-
let members = p.Properties |> Array.filter (fun p -> p.IsPublic)
127+
let members = [|
128+
for prop in p.Properties do if prop.IsPublic then prop
129+
for field in p.Fields do if field.IsPublic then field
130+
|]
128131
addRecursiveToCache (diffReadOnlyFields<'T> custom members Diff.Record) cache
129132
| Shape.Equality e ->
130133
{ new IEqualityVisitor<IDiffer<'T>> with

tests/Diffract.CSharp.Tests/Tests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ public void Poco()
1313
Differ.ToString(expected, actual));
1414
}
1515

16+
[Fact]
17+
public void FieldPoco()
18+
{
19+
var expected = new MyFieldPoco(1, "a");
20+
var actual = new MyFieldPoco(2, "a");
21+
Assert.Equal("X Expect = 1\n Actual = 2\n",
22+
Differ.ToString(expected, actual));
23+
}
24+
1625
[Fact]
1726
public void Record()
1827
{
@@ -41,6 +50,18 @@ public class MyPoco
4150
public MyInnerPoco Item { get; init; }
4251
}
4352

53+
public class MyFieldPoco
54+
{
55+
public int X;
56+
public string Y;
57+
58+
public MyFieldPoco(int x, string y)
59+
{
60+
X = x;
61+
Y = y;
62+
}
63+
}
64+
4465
public record MyRecord(int X, string Y);
4566
}
4667
}

0 commit comments

Comments
 (0)