Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V10 assorted improvements #2039

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions Realm/Realm/Dynamic/MetaRealmObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
MethodInfo getter = null;
if (property.Type.UnderlyingType() == PropertyType.LinkingObjects)
{
arguments.Add(Expression.Constant(_metadata.ComputedProperties[property.Name]));
arguments.Add(Expression.Constant(_metadata.PropertyIndices[property.Name]));
getter = GetGetMethod(DummyHandle.GetBacklinks);
}
else if (property.Type.IsArray())
{
arguments.Add(Expression.Field(GetLimitedSelf(), RealmObjectRealmField));
arguments.Add(Expression.Constant(_metadata.ColumnKeys[property.Name]));
arguments.Add(Expression.Constant(_metadata.PropertyIndices[property.Name]));
arguments.Add(Expression.Constant(property.ObjectType, typeof(string)));
switch (property.Type.UnderlyingType())
{
Expand Down Expand Up @@ -144,7 +144,7 @@ public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
}
else
{
arguments.Add(Expression.Constant(_metadata.ColumnKeys[property.Name]));
arguments.Add(Expression.Constant(_metadata.PropertyIndices[property.Name]));
switch (property.Type.UnderlyingType())
{
case PropertyType.Int:
Expand Down Expand Up @@ -186,7 +186,6 @@ public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
else
{
expression = Expression.Call(self, RealmObjectGetBacklinksForHandle_RealmObject, Expression.Constant(binder.Name), expression);

}
}

Expand Down Expand Up @@ -214,7 +213,7 @@ public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicM

var arguments = new List<Expression>
{
Expression.Constant(_metadata.ColumnKeys[property.Name])
Expression.Constant(_metadata.PropertyIndices[property.Name])
};

MethodInfo setter = null;
Expand Down Expand Up @@ -306,24 +305,22 @@ private bool IsTargetEmbedded(Property property)
return metadata.Schema.IsEmbedded;
}

// GetString(colKey)
// GetByteArray(colKey)
private static MethodInfo GetGetMethod<TResult>(Func<ColumnKey, TResult> @delegate) => @delegate.GetMethodInfo();

// GetPrimitive(colKey, propertyType)
private static MethodInfo GetGetMethod<TResult>(Func<ColumnKey, PropertyType, TResult> @delegate) => @delegate.GetMethodInfo();

// GetString(propertyIndex)
// GetByteArray(propertyIndex)
// GetBacklinks(propertyIndex)
private static MethodInfo GetGetMethod<TResult>(Func<IntPtr, TResult> @delegate) => @delegate.GetMethodInfo();

// GetList(realm, colKey, objectType)
// GetObject(realm, colKey, objectType)
private static MethodInfo GetGetMethod<TResult>(Func<Realm, ColumnKey, string, TResult> @delegate) => @delegate.GetMethodInfo();
// GetPrimitive(propertyIndex, propertyType)
private static MethodInfo GetGetMethod<TResult>(Func<IntPtr, PropertyType, TResult> @delegate) => @delegate.GetMethodInfo();

// GetList(realm, propertyIndex, objectType)
// GetObject(realm, propertyIndex, objectType)
private static MethodInfo GetGetMethod<TResult>(Func<Realm, IntPtr, string, TResult> @delegate) => @delegate.GetMethodInfo();

// SetXXX(colKey)
private static MethodInfo GetSetMethod<TValue>(Action<ColumnKey, TValue> @delegate) => @delegate.GetMethodInfo();
// SetXXX(propertyIndex)
private static MethodInfo GetSetMethod<TValue>(Action<IntPtr, TValue> @delegate) => @delegate.GetMethodInfo();

// SetObject(this, colKey)
private static MethodInfo GetSetMethod<TValue>(Action<Realm, ColumnKey, TValue> @delegate) => @delegate.GetMethodInfo();
// SetObject(this, propertyIndex)
private static MethodInfo GetSetMethod<TValue>(Action<Realm, IntPtr, TValue> @delegate) => @delegate.GetMethodInfo();
}
}
24 changes: 12 additions & 12 deletions Realm/Realm/Handles/ListHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ private static class NativeMethods

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_add_string", CallingConvention = CallingConvention.Cdecl)]
public static extern void add_string(ListHandle listHandle, [MarshalAs(UnmanagedType.LPWStr)] string value, IntPtr valueLength,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_add_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern void add_binary(ListHandle listHandle, IntPtr buffer, IntPtr bufferLength,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_add_embedded", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr add_embedded(ListHandle listHandle, out NativeException ex);
Expand All @@ -63,11 +63,11 @@ public static extern void add_binary(ListHandle listHandle, IntPtr buffer, IntPt

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_set_string", CallingConvention = CallingConvention.Cdecl)]
public static extern void set_string(ListHandle listHandle, IntPtr targetIndex, [MarshalAs(UnmanagedType.LPWStr)] string value,
IntPtr valueLen, [MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
IntPtr valueLen, [MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_set_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern void set_binary(ListHandle listHandle, IntPtr targetIndex, IntPtr buffer, IntPtr bufferLength,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_set_embedded", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr set_embedded(ListHandle listHandle, IntPtr targetIndex, out NativeException ex);
Expand All @@ -86,11 +86,11 @@ public static extern void set_binary(ListHandle listHandle, IntPtr targetIndex,

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_insert_string", CallingConvention = CallingConvention.Cdecl)]
public static extern void insert_string(ListHandle listHandle, IntPtr targetIndex, [MarshalAs(UnmanagedType.LPWStr)] string value,
IntPtr valueLen, [MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
IntPtr valueLen, [MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_insert_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern void insert_binary(ListHandle listHandle, IntPtr targetIndex, IntPtr buffer, IntPtr bufferLength,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_insert_embedded", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr insert_embedded(ListHandle listHandle, IntPtr targetIndex, out NativeException ex);
Expand All @@ -107,11 +107,11 @@ public static extern void insert_binary(ListHandle listHandle, IntPtr targetInde

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_get_string", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr get_string(ListHandle listHandle, IntPtr link_ndx, IntPtr buffer, IntPtr bufsize,
[MarshalAs(UnmanagedType.I1)] out bool isNull, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] out bool isNull, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_get_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr get_binary(ListHandle listHandle, IntPtr link_ndx, IntPtr buffer, IntPtr bufsize,
[MarshalAs(UnmanagedType.I1)] out bool isNull, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] out bool isNull, out NativeException ex);

#endregion

Expand All @@ -127,11 +127,11 @@ public static extern IntPtr get_binary(ListHandle listHandle, IntPtr link_ndx, I

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_find_string", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr find_string(ListHandle listHandle, [MarshalAs(UnmanagedType.LPWStr)] string value, IntPtr valueLen,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_find_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr find_binary(ListHandle listHandle, IntPtr buffer, IntPtr bufsize,
[MarshalAs(UnmanagedType.I1)] bool has_value, out NativeException ex);
[MarshalAs(UnmanagedType.U1)] bool has_value, out NativeException ex);

#endregion

Expand All @@ -154,7 +154,7 @@ public static extern IntPtr find_binary(ListHandle listHandle, IntPtr buffer, In
public static extern IntPtr move(ListHandle listHandle, IntPtr sourceIndex, IntPtr targetIndex, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_get_is_valid", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool get_is_valid(ListHandle listHandle, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_get_thread_safe_reference", CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -164,7 +164,7 @@ public static extern IntPtr find_binary(ListHandle listHandle, IntPtr buffer, In
public static extern IntPtr snapshot(ListHandle list, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_get_is_frozen", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool get_is_frozen(ListHandle list, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "list_freeze", CallingConvention = CallingConvention.Cdecl)]
Expand Down
Loading