RealmValue - .NET SDK
On this page
New in version 10.2.0.
Overview
The RealmValue
data type is a mixed data type, and can represent any
other valid Realm data type except a collection. You can create collections
(lists, sets, and dictionaries) of type RealmValue
, but a RealmValue
itself cannot be a collection:
// CS0029 - Cannot implicitly convert type: RealmValue myList = new List<Inventory>(); // These are valid uses of RealmValue: var rvList = new List<RealmValue>(); var rvDict = new Dictionary<string, RealmValue>();
Note
You cannot create a nullable RealmValue
. However, if you want a
RealmValue
property to contain a null value, you can
use the special RealmValue.Null
property.
The following code demonstrates creating a RealmValue
property in a class
that inherits from IRealmObject
and then setting and getting the value of
that property:
public partial class MyRealmValueObject : IRealmObject { [ ] [ ] public Guid Id { get; set; } public RealmValue MyValue { get; set; } // A nullable RealmValue property is *not supported* // public RealmValue? NullableRealmValueNotAllowed { get; set; } private void TestRealmValue() { var obj = new MyRealmValueObject(); // set the value to null: obj.MyValue = RealmValue.Null; // or an int... obj.MyValue = 1; // or a string... obj.MyValue = "abc"; // Use RealmValueType to check the type: if (obj.MyValue.Type == RealmValueType.String) { var myString = obj.MyValue.AsString(); } }