Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding comment on the ordering of fields and properties. Added unit t…
…est for field/property ordering.
  • Loading branch information
skent-mz committed Nov 17, 2022
commit be3674a958e24c4d91cf179b786b7efdde576650
23 changes: 23 additions & 0 deletions SQLite.Net.Tests/FieldSupportTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using NUnit.Framework;

namespace SQLite.Net2.Tests
Expand All @@ -15,6 +16,9 @@ public class FieldTestModel
protected internal int shouldNotBeSet2 = -2;

public string Role { get; set; }

public int IgnoredProp1 { get; }
public int IgnoredProp2 { private get; set; }

public void AssertNotSet()
{
Expand All @@ -27,6 +31,25 @@ public void AssertNotSet()
[TestFixture]
public class FieldSupportTest : BaseTest
{
[Test]
public void FieldBeforePropertyOrdering()
{
string[] fieldNames = {
nameof(FieldTestModel.id),
nameof(FieldTestModel.name),
nameof(FieldTestModel.shouldNotBeSet0),
nameof(FieldTestModel.Role)
};

var members = ReflectionService.GetPublicInstanceProperties(typeof(FieldTestModel)).ToList();

Assert.That(members.Count, Is.EqualTo(fieldNames.Length));
for (var i = 0; i < fieldNames.Length; ++i)
{
Assert.That(members[i].Name, Is.EqualTo(fieldNames[i]));
}
}

[Test]
public void CanCreateModelWithFields()
{
Expand Down
4 changes: 4 additions & 0 deletions src/SQLite.Net/Interop/ReflectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace SQLite.Net2
{
public static class ReflectionService
{
/// <summary>
/// Returns the set of public non-static non-initonly fields followed by the public non-static properties with
/// public get and set methods.
/// </summary>
public static IEnumerable<MemberInfo> GetPublicInstanceProperties(Type mappedType)
{
var properties = mappedType.GetTypeInfo().GetRuntimeProperties()
Expand Down