Skip to content

Commit

Permalink
Move generated accessors onto user-defined classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j committed Jul 11, 2024
1 parent b5bad45 commit 11da026
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions Tests/Realm.Tests/Database/FlexibleSchemaPocTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,29 +224,33 @@ public FlexibleSchemaPocContainer(string containedObjectType)
}
}

// User-defined
// User-defined(ish)
public partial class Dog : IMappedObject
{
// User-defined
// public string Name { get; set; }

// public int BarkCount { get; set; }
}

// Generated
public partial class Dog : IMappedObject
{
// Generated
public string Name
{
get => Get<string>(nameof(Name));
set => Set(nameof(Name), value);
}

// User-defined
// public int BarkCount { get; set; }

// Generated
public int BarkCount
{
get => Get<int>(nameof(BarkCount));
set => Set(nameof(BarkCount), value);
}
}

// Generated (partial)
public partial class Dog : IMappedObject
{
private T Get<T>(string propertyName)
{
Argument.Ensure(_backingStorage.TryGetValue(propertyName, out var value), $"A property with name '{propertyName}' does not exist on '{nameof(Dog)}'.", nameof(propertyName));
Expand All @@ -260,29 +264,33 @@ private void Set(string propertyName, RealmValue value)
}
}

// User-defined
// User-defined(ish)
public partial class Bird : IMappedObject
{
// User-defined
// public string Name { get; set; }

// public bool CanFly { get; set; }
}

// Generated
public partial class Bird : IMappedObject
{
// Generated
public string Name
{
get => Get<string>(nameof(Name));
set => Set(nameof(Name), value);
}

// User-defined
// public bool CanFly { get; set; }

// Generated
public bool CanFly
{
get => Get<bool>(nameof(CanFly));
set => Set(nameof(CanFly), value);
}
}

// Generated (partial)
public partial class Bird : IMappedObject
{
private T Get<T>(string propertyName)
{
Argument.Ensure(_backingStorage.TryGetValue(propertyName, out var value), $"A property with name '{propertyName}' does not exist on '{nameof(Bird)}'.", nameof(propertyName));
Expand Down

0 comments on commit 11da026

Please sign in to comment.