You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use IDictionary<string, RealmValue> - RealmValue can be any supported type, including a list. However, it doesn't provide type safety in the sense, that both Realm and the type system will happily accept non-string[] types here. If you want to enforce this type, then that is not supported out of the box. You can create a hacky wrapper on top of IDictionary<string, RealmValue>, but that will work on the application rather than the database layer. Here's a rough sketch of the idea:
publicpartialclassDataContainer:IRealmObject{privateLazy<RealmDictionaryWrapper>_dataWrapper=new(()=>new(StorageDict));// Real backing storage dictionary is private so its inaccessible outside of the classprivateIDictionary<string,RealmValue>StorageDict{get;}// Return the wrapper via the public APIpublicRealmDictionaryWrapperData=>_dataWrapper.Value;}publicclassRealmDictionaryWrapper:IDictionary<string,string[]>{privatereadonlyIDictionary<string,RealmValue>_backingStorage;publicRealmDictionaryWrapper(IDictionary<string,RealmValue>storage){_backingStorage=storage;}publicintCount=>_backingStorage.Count;publicvoidAdd(stringkey,string[]value){_backingStorage.Add(key,value.Select(a =>(RealmValue)a).ToArray());}publicboolContainsKey(stringkey)=>_backingStorage.ContainsKey(key);publicboolRemove(stringkey)=>_backingStorage.Remove(key);publicboolTryGetValue(stringkey,outstring[]value){if(_backingStorage.TryGetValue(key,outvarbackingValue)){// This doesn't do any error handling - in case the backingValue is not a list or// its elements are not strings, this will throw.value=backingValue.AsList().Select(v =>v.AsString()).ToArray();returntrue;}value=default;returnfalse;}// ... remaining IDictionary members}
Problem
XXX is an IDictionary but its generic type is String[] which is not supported by Realm
Example data:
which have type of
Dictionary<string, string[]>
and it not support by Realm.Does Realm currently have any way to work with the data schema like so?
Solution
No response
Alternatives
No response
How important is this improvement for you?
Would be a major improvement
Feature would mainly be used with
Local Database only
The text was updated successfully, but these errors were encountered: