Skip to content

Commit cde9982

Browse files
committed
Copy Custom Modifiers instead of handling init property explicitly
1 parent b9b1394 commit cde9982

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/NHibernate.Test/StaticProxyTest/IsExternalInit.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.ComponentModel;
1+
#if !NET5_0_OR_GREATER
2+
using System.ComponentModel;
23

4+
// ReSharper disable once CheckNamespace
35
namespace System.Runtime.CompilerServices
46
{
57
/// <summary>
@@ -11,3 +13,4 @@ internal static class IsExternalInit
1113
{
1214
}
1315
}
16+
#endif

src/NHibernate/Proxy/DefaultDynamicProxyMethodCheckerExtensions.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,17 @@ public static bool IsProxiable(this MethodInfo method)
1717
((method.IsPublic || method.IsFamily) && (method.IsVirtual || method.IsAbstract)) // public or protected (virtual)
1818
||
1919
(method.IsFamilyOrAssembly && (method.IsVirtual || method.IsAbstract)) // internal protected virtual
20-
)
21-
&& !method.IsPropertyInit();
22-
}
23-
24-
public static bool IsPropertyInit(this MethodInfo method)
25-
{
26-
return method.IsSpecialName &&
27-
method.IsHideBySig &&
28-
method.ReturnParameter.GetRequiredCustomModifiers().Any(n => n.FullName == "System.Runtime.CompilerServices.IsExternalInit");
20+
);
2921
}
3022

3123
public static bool ShouldBeProxiable(this MethodInfo method)
3224
{
3325
// to use only for real methods (no getter/setter)
3426
return (method.DeclaringType != typeof (MarshalByRefObject)) &&
35-
(method.DeclaringType != typeof (object) || !"finalize".Equals(method.Name, StringComparison.OrdinalIgnoreCase)) &&
36-
(!(method.DeclaringType == typeof (object) && "GetType".Equals(method.Name))) &&
37-
(!(method.DeclaringType == typeof (object) && "obj_address".Equals(method.Name))) && // Mono-specific method
38-
!IsDisposeMethod(method) &&
27+
(method.DeclaringType != typeof (object) || !"finalize".Equals(method.Name, StringComparison.OrdinalIgnoreCase)) &&
28+
(!(method.DeclaringType == typeof (object) && "GetType".Equals(method.Name))) &&
29+
(!(method.DeclaringType == typeof (object) && "obj_address".Equals(method.Name))) && // Mono-specific method
30+
!IsDisposeMethod(method) &&
3931
(method.IsPublic || method.IsAssembly || method.IsFamilyOrAssembly);
4032
}
4133

src/NHibernate/Proxy/ProxyBuilderHelper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,18 @@ internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo me
171171
var implementationName = explicitImplementation
172172
? $"{method.DeclaringType.FullName}.{name}"
173173
: name;
174+
174175
var methodBuilder =
175176
typeBuilder.DefineMethod(
176177
implementationName,
177178
methodAttributes,
178179
CallingConventions.HasThis,
179180
method.ReturnType,
180-
parameters.ToArray(param => param.ParameterType));
181+
method.ReturnParameter?.GetRequiredCustomModifiers(),
182+
method.ReturnParameter?.GetOptionalCustomModifiers(),
183+
parameters.ToArray(p => p.ParameterType),
184+
parameters.ToArray(p => p.GetRequiredCustomModifiers()),
185+
parameters.ToArray(p => p.GetOptionalCustomModifiers()));
181186

182187
var typeArgs = method.GetGenericArguments();
183188
if (typeArgs.Length > 0)

0 commit comments

Comments
 (0)