4
4
using System . Reflection ;
5
5
using System . Reflection . Emit ;
6
6
using System . Runtime . Serialization ;
7
+ using System . Security ;
7
8
using NHibernate . Proxy . DynamicProxy ;
8
9
using NHibernate . Type ;
9
10
using NHibernate . Util ;
@@ -29,11 +30,13 @@ class NHibernateProxyBuilder
29
30
static readonly MethodInfo LazyInitializerGetImplementationMethod = LazyInitializerType . GetMethod ( nameof ( ILazyInitializer . GetImplementation ) , System . Type . EmptyTypes ) ;
30
31
static readonly IProxyAssemblyBuilder ProxyAssemblyBuilder = new DefaultProxyAssemblyBuilder ( ) ;
31
32
33
+ static readonly ConstructorInfo SecurityCriticalAttributeConstructor = typeof ( SecurityCriticalAttribute ) . GetConstructor ( System . Type . EmptyTypes ) ;
34
+ static readonly MethodInfo SerializableGetObjectDataMethod = typeof ( ISerializable ) . GetMethod ( nameof ( ISerializable . GetObjectData ) ) ;
35
+
32
36
readonly MethodInfo _getIdentifierMethod ;
33
37
readonly MethodInfo _setIdentifierMethod ;
34
38
readonly IAbstractComponentType _componentIdType ;
35
39
readonly bool _overridesEquals ;
36
-
37
40
public NHibernateProxyBuilder ( MethodInfo getIdentifierMethod , MethodInfo setIdentifierMethod , IAbstractComponentType componentIdType , bool overridesEquals )
38
41
{
39
42
_getIdentifierMethod = getIdentifierMethod ;
@@ -148,8 +151,8 @@ static void ImplementGetObjectData(TypeBuilder typeBuilder, FieldInfo proxyFacto
148
151
MethodAttributes . Virtual ;
149
152
var parameterTypes = new [ ] { typeof ( SerializationInfo ) , typeof ( StreamingContext ) } ;
150
153
151
- var methodBuilder =
152
- typeBuilder . DefineMethod ( "GetObjectData" , attributes , typeof ( void ) , parameterTypes ) ;
154
+ var methodBuilder = typeBuilder . DefineMethod ( "GetObjectData" , attributes , typeof ( void ) , parameterTypes ) ;
155
+ methodBuilder . SetCustomAttribute ( new CustomAttributeBuilder ( SecurityCriticalAttributeConstructor , Array . Empty < object > ( ) ) ) ;
153
156
154
157
var IL = methodBuilder . GetILGenerator ( ) ;
155
158
//LocalBuilder proxyBaseType = IL.DeclareLocal(typeof(Type));
@@ -179,9 +182,11 @@ static void ImplementGetObjectData(TypeBuilder typeBuilder, FieldInfo proxyFacto
179
182
IL . Emit ( OpCodes . Ldarg_1 ) ;
180
183
IL . Emit ( OpCodes . Ldarg_2 ) ;
181
184
182
- IL . Emit ( OpCodes . Callvirt , typeof ( ISerializable ) . GetMethod ( nameof ( ISerializable . GetObjectData ) ) ) ;
185
+ IL . Emit ( OpCodes . Callvirt , SerializableGetObjectDataMethod ) ;
183
186
184
187
IL . Emit ( OpCodes . Ret ) ;
188
+
189
+ typeBuilder . DefineMethodOverride ( methodBuilder , SerializableGetObjectDataMethod ) ;
185
190
}
186
191
187
192
public void CreateProxiedMethod ( FieldInfo lazyInitializerField , MethodInfo method , TypeBuilder typeBuilder )
0 commit comments