Skip to content

Commit

Permalink
Small corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
papafe committed Jul 25, 2024
1 parent 819b9aa commit cbbe6c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 1 addition & 11 deletions Realm/Realm/DatabaseTypes/Accessors/ManagedAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ protected ManagedAccessor()
#pragma warning restore CS8618
{
_hashCode = new(() => ObjectHandle!.GetObjHash());
_objectSchema = new(() =>
{
if (Realm!.Config.RelaxedSchema)
{
var objSchemaCopy = Metadata!.Schema.GetBuilder().Build();
objSchemaCopy.ObjectHandle = ObjectHandle;
return objSchemaCopy;
}

return Metadata!.Schema;
});
_objectSchema = new(() => Realm!.Config.RelaxedSchema ? Metadata!.Schema.MakeCopyWithHandle(ObjectHandle!) : Metadata!.Schema);
}

[MemberNotNull(nameof(Realm), nameof(ObjectHandle), nameof(Metadata))]
Expand Down
12 changes: 12 additions & 0 deletions Realm/Realm/Schema/ObjectSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ internal ObjectSchema(string name, ObjectType schemaType, IDictionary<string, Pr
}
}

internal ObjectSchema(ObjectSchema schema, ObjectHandle objectHandle)
{
Name = schema.Name;
BaseType = schema.BaseType;
PrimaryKeyProperty = schema.PrimaryKeyProperty;
ObjectHandle = objectHandle;
_properties = schema.Properties;
}

//TODO This seems to not have references, need to try to remove it and see if anything fails
internal ObjectSchema(in SchemaObject native)
{
Expand Down Expand Up @@ -209,6 +218,9 @@ internal static ObjectSchema FromType(Type type)
primary_key = StringValue.AllocateFrom(PrimaryKeyProperty?.Name, arena)
};

// TODO We could remove this or the new constructor
internal ObjectSchema MakeCopyWithHandle(ObjectHandle handle) => new(this, handle);

/// <summary>
/// A mutable builder that allows you to construct an <see cref="ObjectSchema"/> instance.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Tests/Realm.Tests/Database/DynamicAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;
Expand Down Expand Up @@ -480,6 +479,7 @@ public void GetProperty_WhenPropertyIsMissing_Throws()
RunTestInAllModes((realm, _) =>
{
var allTypesObject = realm.Write(() => realm.DynamicApi.CreateObject(nameof(AllTypesObject)));

Assert.Throws<MissingMemberException>(() => allTypesObject.DynamicApi.Get<string>("idontexist"));
});
}
Expand Down Expand Up @@ -572,6 +572,7 @@ public void SetProperty_WhenPropertyIsMissing_Throws()
realm.Write(() =>
{
var ato = realm.DynamicApi.CreateObject(nameof(AllTypesObject));

Assert.Throws<MissingMemberException>(() => ato.DynamicApi.Set("idontexist", "foo"));
});
});
Expand Down

0 comments on commit cbbe6c3

Please sign in to comment.