Skip to content

Commit

Permalink
Improved handling of lists and objects
Browse files Browse the repository at this point in the history
  • Loading branch information
papafe committed Jun 18, 2024
1 parent faa7df0 commit f532c84
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 17 deletions.
10 changes: 8 additions & 2 deletions Realm/Realm/Dynamic/DynamicObjectApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ internal DynamicObjectApi(ManagedAccessor managedAccessor)
/// object, casting to <see cref="IRealmObjectBase"/> is always valid.
/// </remarks>
public T Get<T>(string propertyName)
{
return Get(propertyName).As<T>();
}

//TODO Add docs

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Verify TODOs

Realm/Realm/Dynamic/DynamicObjectApi.cs#L60

TODO entry doesn't have a link to Github issue or Jira ticket Add docs

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Source Generation

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Single line comment should begin with a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1005.md) [/home/runner/work/realm-dotnet/realm-dotnet/Realm/Realm/Realm.csproj::TargetFramework=net8.0]

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

Check warning on line 60 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

public RealmValue Get(string propertyName)

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Source Generation

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Elements should be documented (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1600.md) [/home/runner/work/realm-dotnet/realm-dotnet/Realm/Realm/Realm.csproj::TargetFramework=net8.0]

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 61 in Realm/Realm/Dynamic/DynamicObjectApi.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

{
if (GetProperty(propertyName) is Property property)
{
Expand All @@ -76,11 +82,11 @@ public T Get<T>(string propertyName)
$"{_managedAccessor.ObjectSchema.Name}.{propertyName} is {property.GetDotnetTypeName()} and can't be accessed using {nameof(Dynamic)}.{nameof(Get)}. Use {collectionMethodName} instead.");
}

return _managedAccessor.GetValue(propertyName).As<T>();
return _managedAccessor.GetValue(propertyName);
}
else
{
return _managedAccessor.GetValue(propertyName).As<T>();
return _managedAccessor.GetValue(propertyName);
}
}

Expand Down
40 changes: 38 additions & 2 deletions Realm/Realm/Handles/ObjectHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ private static class NativeMethods
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "object_set_collection_value", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr set_collection_value(ObjectHandle handle, IntPtr propertyIndex, RealmValueType type, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "object_set_collection_additional_property", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr set_collection_additional_property(ObjectHandle handle, StringValue propertyName, RealmValueType type, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "object_create_embedded", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr create_embedded_link(ObjectHandle handle, IntPtr propertyIndex, out NativeException ex);

Expand Down Expand Up @@ -269,17 +272,50 @@ public void SetValue(string propertyName, Metadata metadata, in RealmValue value
}
else
{
//TODO Eventually merge with the previous case

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Verify TODOs

Realm/Realm/Handles/ObjectHandle.cs#L275

TODO entry doesn't have a link to Github issue or Jira ticket Eventually merge with the previous case

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Source Generation

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Single line comment should begin with a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1005.md) [/home/runner/work/realm-dotnet/realm-dotnet/Realm/Realm/Realm.csproj::TargetFramework=net8.0]

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

Check warning on line 275 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Package NuGet


//TODO Probably this can be improved

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Verify TODOs

Realm/Realm/Handles/ObjectHandle.cs#L277

TODO entry doesn't have a link to Github issue or Jira ticket Probably this can be improved

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (macos-14, osx-arm64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Source Generation

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Weaver (windows-latest, win-x64)

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Single line comment should begin with a space. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1005.md) [/home/runner/work/realm-dotnet/realm-dotnet/Realm/Realm/Realm.csproj::TargetFramework=net8.0]

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

Check warning on line 277 in Realm/Realm/Handles/ObjectHandle.cs

View workflow job for this annotation

GitHub Actions / Package NuGet

using Arena arena = new();
var propertyNameNative = StringValue.AllocateFrom(propertyName, arena);

if (value.Type == RealmValueType.Object)
{
switch (value.AsIRealmObject())
{
case IRealmObject realmObj when !realmObj.IsManaged:
realm.Add(realmObj);
break;
case IEmbeddedObject:
throw new NotSupportedException($"A RealmValue cannot contain an embedded object. Attempted to set {value} to {metadata.Schema.Name}.{propertyName}");
case IAsymmetricObject:
throw new NotSupportedException($"Asymmetric objects cannot be linked to and cannot be contained in a RealmValue. Attempted to set {value} to {metadata.Schema.Name}.{propertyName}");
}
}
else if (value.Type.IsCollection())
{
var collectionPtr = NativeMethods.set_collection_additional_property(this, propertyNameNative, value.Type, out var collNativeException);
collNativeException.ThrowIfNecessary();

switch (value.Type)
{
case RealmValueType.List:
CollectionHelpers.PopulateCollection(realm, new ListHandle(Root!, collectionPtr), value);
break;
case RealmValueType.Dictionary:
CollectionHelpers.PopulateCollection(realm, new DictionaryHandle(Root!, collectionPtr), value);
break;
default:
break;
}

return;
}

var (primitive, handles) = value.ToNative();
NativeMethods.set_additional_property(this, propertyNameNative, primitive, out var nativeException);
handles?.Dispose();
nativeException.ThrowIfNecessary();
}


}

public long AddInt64(IntPtr propertyIndex, long value)
Expand Down
33 changes: 27 additions & 6 deletions Tests/Realm.Tests/Database/DynamicAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;
Expand Down Expand Up @@ -983,21 +984,41 @@ public void GetDictionary_WhenCastToWrongValue_Throws()
[Test]
public void FlexibleSchema_BaseTest()
{
var testObj = _realm.Write(() =>
var person = _realm.Write(() =>
{
return _realm.Add(new IntPropertyObject());
return _realm.Add(new Person());
});

var testObj = new Person { FirstName = "Luigi" };
var testList = new List<RealmValue> { 1, "test", true };

_realm.Write(() =>
{
testObj.DynamicApi.Set("prop1", "testval");
testObj.DynamicApi.Set("prop2", 10);
person.DynamicApi.Set("propString", "testval");
person.DynamicApi.Set("propInt", 10);
person.DynamicApi.Set("propObj", testObj);
person.DynamicApi.Set("propList", testList);
});

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

A closing brace should not be preceded by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1508.md) [/home/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, linux-x64

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, osx-x64

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Woven Classes

A closing brace should not be preceded by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1508.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, win-x64

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework

A closing brace should not be preceded by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1508.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net461]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.macOS

A closing brace should not be preceded by a blank line [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test UWP

A closing brace should not be preceded by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1508.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.tvOS

A closing brace should not be preceded by a blank line [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.iOS

A closing brace should not be preceded by a blank line [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.Android

A closing brace should not be preceded by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1508.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.Android

Check warning on line 1002 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net8.0, osx-arm64


Assert.That(testObj.DynamicApi.Get<string>("prop1"), Is.EqualTo("testval"));
Assert.That(testObj.DynamicApi.Get<int>("prop2"), Is.EqualTo(10));
Assert.That(person.DynamicApi.Get<string>("propString"), Is.EqualTo("testval"));
Assert.That(person.DynamicApi.Get<int>("propInt"), Is.EqualTo(10));
Assert.That(person.DynamicApi.Get<Person>("propObj"), Is.EqualTo(testObj));
Assert.That(person.DynamicApi.Get<IList<RealmValue>>("propList"), Is.EqualTo(testList));
}

/** To test
* - add and retrieve objects
* - add and retrieve collections
* - set on same property changes
* - set null value
* - retrieve property that does not exist raises exception
* - retrieve additional properties
* - erase a property
*

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [/home/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, linux-x64

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, osx-x64

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Woven Classes

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, win-x64

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net461]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.macOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test UWP

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.tvOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.iOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.Android

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.Android

Check warning on line 1018 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net8.0, osx-arm64

*

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [/home/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, linux-x64

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, osx-x64

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Woven Classes

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, win-x64

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net461]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.macOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test UWP

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.tvOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.iOS

Code should not contain trailing whitespace [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.Android

Code should not contain trailing whitespace (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1028.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.Android

Check warning on line 1019 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net8.0, osx-arm64

*/

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Code Coverage

Code should not contain multiple blank lines in a row (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1507.md) [/home/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, linux-x64

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, osx-x64

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Woven Classes

Code should not contain multiple blank lines in a row (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1507.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net8.0]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net6.0, win-x64

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework

Code should not contain multiple blank lines in a row (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1507.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=net461]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.macOS

Code should not contain multiple blank lines in a row [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test UWP

Code should not contain multiple blank lines in a row (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1507.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.tvOS

Code should not contain multiple blank lines in a row [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.iOS

Code should not contain multiple blank lines in a row [/Users/runner/work/realm-dotnet/realm-dotnet/Tests/Realm.Tests/Realm.Tests.csproj]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.MacCatalyst

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Xamarin.Android

Code should not contain multiple blank lines in a row (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1507.md) [D:\a\realm-dotnet\realm-dotnet\Tests\Realm.Tests\Realm.Tests.csproj::TargetFramework=netstandard2.0]

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.iOS

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test Maui.Android

Check warning on line 1020 in Tests/Realm.Tests/Database/DynamicAccessTests.cs

View workflow job for this annotation

GitHub Actions / Test net8.0, osx-arm64


#endregion

[Test]
Expand Down
55 changes: 48 additions & 7 deletions wrappers/src/object_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extern "C" {
}

auto val = object.get_obj().get_any(prop.column_key);
if (val.is_null())
if (val.is_null()) //TODO I think we don't need this check

Check warning on line 108 in wrappers/src/object_cs.cpp

View workflow job for this annotation

GitHub Actions / Verify TODOs

wrappers/src/object_cs.cpp#L108

TODO entry doesn't have a link to Github issue or Jira ticket I think we don't need this check
{
*value = to_capi(std::move(val));
return;
Expand All @@ -128,14 +128,26 @@ extern "C" {
});
}

REALM_EXPORT void object_get_additional_property(const Object& object, realm_string_t proeprty_name, realm_value_t* value, NativeException::Marshallable& ex)
REALM_EXPORT void object_get_additional_property(const Object& object, realm_string_t property_name, realm_value_t* value, NativeException::Marshallable& ex)
{
handle_errors(ex, [&]() {
verify_can_get(object);

auto val = object.get_obj().get_any(capi_to_std(proeprty_name));
auto val = object.get_obj().get_additional_prop(capi_to_std(property_name));

*value = to_capi(std::move(val));
Path path = { PathElement(capi_to_std(property_name)) };

switch (val.get_type()) {
case type_TypedLink:
*value = to_capi(val.get<ObjLink>(), object.realm());
break;
case type_List:
*value = to_capi(new List(object.realm(), object.get_obj().get_list_ptr<Mixed>(path)));
break;
default:
*value = to_capi(std::move(val));
break;
}
});
}

Expand Down Expand Up @@ -190,9 +202,7 @@ extern "C" {
handle_errors(ex, [&]() {
verify_can_set(object);

//Set_additional_prop is private at the moment

object.get_obj().set_any(capi_to_std(property_name), from_capi(value));
object.get_obj().set_additional_prop(capi_to_std(property_name), from_capi(value));
});
}

Expand Down Expand Up @@ -225,6 +235,37 @@ extern "C" {
});
}

REALM_EXPORT void* object_set_collection_additional_property(Object& object,
realm_string_t property_name, realm_value_type type, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&]()-> void* {
verify_can_set(object);

auto prop = capi_to_std(property_name);

Path path = { PathElement(prop) };

switch (type)
{
case realm::binding::realm_value_type::RLM_TYPE_LIST:
{

object.get_obj().set_collection(prop, CollectionType::List);
//TODO We probably need to ask for methods that do not require to build a path

Check warning on line 254 in wrappers/src/object_cs.cpp

View workflow job for this annotation

GitHub Actions / Verify TODOs

wrappers/src/object_cs.cpp#L254

TODO entry doesn't have a link to Github issue or Jira ticket We probably need to ask for methods that do not require to build a path
auto innerList = new List(object.realm(), object.get_obj().get_list_ptr<Mixed>(path));
innerList->remove_all();
return innerList;
}
case realm::binding::realm_value_type::RLM_TYPE_DICTIONARY:
{
REALM_TERMINATE("Invalid collection type");
}
default:
REALM_TERMINATE("Invalid collection type");
}
});
}

REALM_EXPORT Results* object_get_backlinks(Object& object, size_t property_ndx, NativeException::Marshallable& ex)
{
return handle_errors(ex, [&] {
Expand Down

0 comments on commit f532c84

Please sign in to comment.