Skip to content

Commit

Permalink
Support non-public constructors in entities (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
firenero authored Apr 27, 2024
1 parent b2f487e commit ab8a64e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/EfficientDynamoDb/Internal/Metadata/EmitMemberAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class EmitMemberAccessor
public static Func<object>? CreateConstructor(Type type)
{
Debug.Assert(type != null);
ConstructorInfo? realMethod = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, binder: null, Type.EmptyTypes, modifiers: null);
var realMethod = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, binder: null, Type.EmptyTypes, modifiers: null);

if (type.IsAbstract)
{
Expand All @@ -35,11 +35,11 @@ internal static class EmitMemberAccessor
typeof(EmitMemberAccessor).Module,
skipVisibility: true);

ILGenerator generator = dynamicMethod.GetILGenerator();
var generator = dynamicMethod.GetILGenerator();

if (realMethod == null)
{
LocalBuilder local = generator.DeclareLocal(type);
var local = generator.DeclareLocal(type);

generator.Emit(OpCodes.Ldloca_S, local);
generator.Emit(OpCodes.Initobj, type);
Expand All @@ -50,7 +50,7 @@ internal static class EmitMemberAccessor
{
generator.Emit(OpCodes.Newobj, realMethod);
}

generator.Emit(OpCodes.Ret);

return (Func<object>?)dynamicMethod.CreateDelegate(typeof(Func<object>));
Expand Down

0 comments on commit ab8a64e

Please sign in to comment.