-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -789,13 +789,17 @@ public T AsRealmObject<T>() | |
where T : class, IRealmObjectBase | ||
=> Type == RealmValueType.Null ? null : AsRealmObject<T>(); | ||
|
||
// TODO (ni): add docs | ||
public T AsMappedObject<T>() | ||
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Source Generation
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Package NuGet
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Package NuGet
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Package NuGet
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Analyze C#
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Analyze C#
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Analyze C#
Check warning on line 793 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Code Coverage
|
||
where T : class, IMappedObject | ||
{ | ||
EnsureType("dictionary", RealmValueType.Dictionary); | ||
throw new NotImplementedException(); | ||
var result = Activator.CreateInstance<T>(); | ||
result.SetBackingStorage(_dictionaryValue!); | ||
return result; | ||
} | ||
|
||
// TODO (ni): add docs | ||
public T? AsNullableMappedObject<T>() | ||
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Source Generation
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Package NuGet
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Package NuGet
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Analyze C#
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Analyze C#
Check warning on line 803 in Realm/Realm/DatabaseTypes/RealmValue.cs GitHub Actions / Test Code Coverage
|
||
where T : class, IMappedObject | ||
=> Type == RealmValueType.Null ? null : AsMappedObject<T>(); | ||
|
@@ -815,12 +819,17 @@ public T As<T>() | |
|
||
if (typeof(IMappedObject).IsAssignableFrom(typeof(T))) | ||
{ | ||
return Type switch | ||
switch (Type) | ||
{ | ||
RealmValueType.Null => Operator.Convert<T>(null)!, | ||
RealmValueType.Dictionary => throw new NotImplementedException(), | ||
_ => throw new NotSupportedException($"Can't convert from {Type} to dictionary, which is the backing storage type for {typeof(T)}"), | ||
}; | ||
case RealmValueType.Null: | ||
return Operator.Convert<T>(null)!; | ||
case RealmValueType.Dictionary: | ||
var result = Activator.CreateInstance<T>()!; | ||
((IMappedObject)result).SetBackingStorage(_dictionaryValue!); | ||
return result; | ||
default: | ||
throw new InvalidCastException($"Can't convert from {Type} to dictionary, which is the backing storage type for {typeof(T)}"); | ||
} | ||
} | ||
|
||
// This largely copies AsAny to avoid boxing the underlying value in an object | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -557,6 +557,15 @@ public static async Task<IQueryable<T>> SubscribeAsync<T>(this IQueryable<T> que | |
return query; | ||
} | ||
|
||
// TODO (ni): add docs | ||
public static T As<T>(this IDictionary<string, RealmValue> dict) | ||
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (ubuntu-latest, linux-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (macos-14, osx-arm64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Source Generation
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Package NuGet
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Package NuGet
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Weaver (windows-latest, win-x64)
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Analyze C#
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Analyze C#
Check warning on line 561 in Realm/Realm/Extensions/CollectionExtensions.cs GitHub Actions / Test Code Coverage
|
||
where T : IMappedObject | ||
{ | ||
var result = Activator.CreateInstance<T>(); | ||
result.SetBackingStorage(dict); | ||
return result; | ||
} | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", | ||
Justification = "This is only used by the weaver/source generated classes and should not be exposed to users.")] | ||
|