Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide collections in mixed from public API #3575

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 0 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
* Opening realm with file format 23 or lower (Realm .NET versions earlier than 12.0.0) in read-only mode will crash. (Core 14.0.0)

### Enhancements
* Added support for list and dictionaries of `RealmValue` (`IList<RealmValue>` and `IDictionary<string, RealmValue>`) to be contained in a `RealmValue`. Lists and dictionaries can contain an arbitrary number of collections themselves. It is possible to convert an existing collection to a `RealmValue` using the new static methods `RealmValue.List` and `RealmValue.Dictionary` or using the implicit operators if converting from common types like `List`, `RealmValue[]` or `Dictionary`. Finally, it is possible to obtain the contained collections by using the new conversion method `AsList` and `AsDictionary`. For example:

```csharp
var list = new List<RealmValue> { 1, true, "stringVal" };

var rvo = realm.Write(() =>
{
return realm.Add(new RealmValueObject { RealmValueProperty = list});
});

var retrievedList = rvo.RealmValueProperty.AsList();
```
(PR [#3441](https://github.com/realm/realm-dotnet/pull/3441))
* Reduced memory usage of `RealmValue`. (PR [#3441](https://github.com/realm/realm-dotnet/pull/3441))
* Add support for passing a key paths collection (`KeyPathsCollection`) when using `IRealmCollection.SubscribeForNotifications`. Passing a `KeyPathsCollection` allows to specify which changes in properties should raise a notification.

Expand Down
48 changes: 24 additions & 24 deletions Realm/Realm/DatabaseTypes/RealmValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
/// <returns> A new RealmValue representing the input list. </returns>
/// <remarks> Once created, this RealmValue will just wrap the input collection.
/// After the object containing this RealmValue gets managed this value will be a Realm list.</remarks>
public static RealmValue List(IList<RealmValue> value) => new(value);
internal static RealmValue List(IList<RealmValue> value) => new(value);

/// <summary>
/// Gets a RealmValue representing a dictionary.
Expand All @@ -226,7 +226,7 @@
/// <returns> A new RealmValue representing the input dictionary. </returns>
/// <remarks> Once created, this RealmValue will just wrap the input collection.
/// After the object containing this RealmValue gets managed this value will be a Realm dictionary.</remarks>
public static RealmValue Dictionary(IDictionary<string, RealmValue> value) => new(value);
internal static RealmValue Dictionary(IDictionary<string, RealmValue> value) => new(value);

internal static RealmValue Create<T>(T value, RealmValueType type)
{
Expand Down Expand Up @@ -510,7 +510,7 @@
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if the underlying value is not of type <see cref="RealmValueType.List"/>.</exception>
/// <returns> A list representing the value stored in the database.</returns>
public IList<RealmValue> AsList()
internal IList<RealmValue> AsList()
{
EnsureType("List", RealmValueType.List);
return _listValue!;
Expand All @@ -521,7 +521,7 @@
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if the underlying value is not of type <see cref="RealmValueType.Dictionary"/>.</exception>
/// <returns> A dictionary representing the value stored in the database.</returns>
public IDictionary<string, RealmValue> AsDictionary()
internal IDictionary<string, RealmValue> AsDictionary()
{
EnsureType("Dictionary", RealmValueType.Dictionary);
return _dictionaryValue!;
Expand Down Expand Up @@ -1448,26 +1448,26 @@
/// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
public static implicit operator RealmValue(RealmObjectBase? val) => val == null ? Null : Object(val);

/// <summary>
/// Implicitly constructs a <see cref="RealmValue"/> from <see cref="System.Collections.Generic.List{T}">List&lt;RealmValue&gt;?</see>.
/// </summary>
/// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
/// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
public static implicit operator RealmValue(List<RealmValue>? val) => val == null ? Null : List(val);

/// <summary>
/// Implicitly constructs a <see cref="RealmValue"/> from <see cref="RealmValue">RealmValue[]?</see>.
/// </summary>
/// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
/// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
public static implicit operator RealmValue(RealmValue[]? val) => val == null ? Null : List(val);

/// <summary>
/// Implicitly constructs a <see cref="RealmValue"/> from <see cref="System.Collections.Generic.Dictionary{TKey, TValue}">Dictionary&lt;string, RealmValue&gt;</see>.
/// </summary>
/// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
/// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
public static implicit operator RealmValue(Dictionary<string, RealmValue>? val) => val == null ? Null : Dictionary(val);
///// <summary>
///// Implicitly constructs a <see cref="RealmValue"/> from <see cref="System.Collections.Generic.List{T}">List&lt;RealmValue&gt;?</see>.
///// </summary>
///// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
///// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
//public static implicit operator RealmValue(List<RealmValue>? val) => val == null ? Null : List(val);

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Source Generation

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1456 in Realm/Realm/DatabaseTypes/RealmValue.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=net6.0]

///// <summary>
///// Implicitly constructs a <see cref="RealmValue"/> from <see cref="RealmValue">RealmValue[]?</see>.
///// </summary>
///// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
///// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
//public static implicit operator RealmValue(RealmValue[]? val) => val == null ? Null : List(val);

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Source Generation

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1463 in Realm/Realm/DatabaseTypes/RealmValue.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=net6.0]

///// <summary>
///// Implicitly constructs a <see cref="RealmValue"/> from <see cref="System.Collections.Generic.Dictionary{TKey, TValue}">Dictionary&lt;string, RealmValue&gt;</see>.
///// </summary>
///// <param name="val">The value to store in the <see cref="RealmValue"/>.</param>
///// <returns>A <see cref="RealmValue"/> containing the supplied <paramref name="val"/>.</returns>
//public static implicit operator RealmValue(Dictionary<string, RealmValue>? val) => val == null ? Null : Dictionary(val);

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Source Generation

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Source Generation

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

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

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Package / NuGet

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Weaver (macos-latest, osx-x64)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Analyze C#

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.cs

View workflow job for this annotation

GitHub Actions / Test / Code Coverage

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md) [/home/runner/work/realm-dotnet/realm-dotnet/Realm/Realm/Realm.csproj::TargetFramework=net6.0]

Check warning on line 1470 in Realm/Realm/DatabaseTypes/RealmValue.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=net6.0]

private void EnsureType(string target, RealmValueType type)
{
Expand Down
Loading
Loading