public bool TryGet(string key, RealmObjectBase.Metadata metadata, Realm realm, out RealmValue value)
        {
            RealmValue keyValue = key;

            var(primitiveKey, keyHandles) = keyValue.ToNative();
            var containsValue = NativeMethods.try_get_value(this, primitiveKey, out var result, out var nativeException);

            keyHandles?.Dispose();
            nativeException.ThrowIfNecessary();

            if (!containsValue)
            {
                value = default;
                return(false);
            }

            if (result.Type != RealmValueType.Object)
            {
                value = new RealmValue(result);
            }
            else
            {
                var objectHandle = result.AsObject(Root);

                if (metadata == null)
                {
                    throw new NotImplementedException("Mixed objects are not supported yet.");
                }

                value = new RealmValue(realm.MakeObject(metadata, objectHandle));
            }

            return(true);
        }
예제 #2
0
        protected void SetValue(string propertyName, RealmValue val)
        {
            Debug.Assert(IsManaged, "Object is not managed, but managed access was attempted");

            var propertyIndex = _metadata.PropertyIndices[propertyName];

            _objectHandle.SetValue(propertyIndex, val, _realm);
        }
예제 #3
0
        public KeyValuePair <string, TValue> GetValueAtIndex <TValue>(int index, Realm realm)
        {
            NativeMethods.get_at_index(this, (IntPtr)index, out var key, out var primitiveValue, out var ex);
            ex.ThrowIfNecessary();
            var value = new RealmValue(primitiveValue, realm);

            return(new KeyValuePair <string, TValue>(key.AsString(), value.As <TValue>()));
        }
예제 #4
0
        public bool TryGet(string key, Realm realm, out RealmValue value)
        {
            RealmValue keyValue = key;

            var(primitiveKey, keyHandles) = keyValue.ToNative();
            var containsValue = NativeMethods.try_get_value(this, primitiveKey, out var result, out var nativeException);

            keyHandles?.Dispose();
            nativeException.ThrowIfNecessary();

            if (!containsValue)
            {
                value = default;
                return(false);
            }

            value = new RealmValue(result, realm);
            return(true);
        }
        public unsafe ObjectHandle CreateObjectWithPrimaryKey(Property pkProperty, object primaryKey, TableKey tableKey, string parentType, bool update, out bool isNew)
        {
            if (primaryKey == null && !pkProperty.Type.IsNullable())
            {
                throw new ArgumentException($"{parentType}'s primary key is defined as non-nullable, but the value passed is null");
            }

            RealmValue pkValue = pkProperty.Type.ToRealmValueType() switch
            {
                RealmValueType.String => (string)primaryKey,
                RealmValueType.Int => primaryKey == null ? (long?)null : Convert.ToInt64(primaryKey),
                RealmValueType.ObjectId => (ObjectId?)primaryKey,
                RealmValueType.Guid => (Guid?)primaryKey,
                _ => throw new NotSupportedException($"Primary key of type {pkProperty.Type} is not supported"),
            };

            var(primitiveValue, handles) = pkValue.ToNative();
            var result = NativeMethods.create_object_unique(this, tableKey, primitiveValue, update, out isNew, out var ex);

            handles?.Dispose();
            ex.ThrowIfNecessary();
            return(new ObjectHandle(this, result));
        }
예제 #6
0
 protected void SetValueUnique(string propertyName, RealmValue value)
 {
     LogCall($"{nameof(propertyName)} = \"{propertyName}\", {nameof(value)} = {value}");
 }