@@ -17,7 +17,6 @@ public sealed class FieldInterceptorObjectReference : IObjectReference, ISeriali
17
17
private readonly object _deserializedProxy ;
18
18
19
19
private const string HasAdditionalDataName = "proxy$hasAdditionalData" ;
20
- private const string AdditionalMemberName = "proxy$additionalMembers" ;
21
20
22
21
public FieldInterceptorObjectReference ( NHibernateProxyFactoryInfo proxyFactoryInfo , IFieldInterceptor fieldInterceptorField )
23
22
{
@@ -30,39 +29,36 @@ private FieldInterceptorObjectReference(SerializationInfo info, StreamingContext
30
29
_proxyFactoryInfo = info . GetValue < NHibernateProxyFactoryInfo > ( nameof ( _proxyFactoryInfo ) ) ;
31
30
_fieldInterceptor = info . GetValue < IFieldInterceptor > ( nameof ( _fieldInterceptor ) ) ;
32
31
32
+ var proxy = _proxyFactoryInfo . CreateProxyFactory ( ) . GetFieldInterceptionProxy ( null ) ;
33
33
if ( info . GetBoolean ( HasAdditionalDataName ) )
34
34
{
35
- _deserializedProxy = _proxyFactoryInfo . CreateProxyFactory ( ) . GetFieldInterceptionProxy ( null ) ;
36
-
37
- var additionalMembers = info . GetValue < MemberInfo [ ] > ( AdditionalMemberName ) ;
38
- if ( additionalMembers == null )
39
- return ;
40
-
41
- foreach ( var member in additionalMembers )
35
+ var members = FormatterServices . GetSerializableMembers ( _proxyFactoryInfo . PersistentClass , context ) ;
36
+ foreach ( var member in members )
42
37
{
43
38
switch ( member )
44
39
{
45
40
case FieldInfo field :
46
41
field . SetValue (
47
- _deserializedProxy ,
42
+ proxy ,
48
43
info . GetValue ( GetAdditionalMemberName ( field ) , field . FieldType ) ) ;
49
44
break ;
50
45
case PropertyInfo property :
51
46
property . SetValue (
52
- _deserializedProxy ,
47
+ proxy ,
53
48
info . GetValue ( GetAdditionalMemberName ( property ) , property . PropertyType ) ) ;
54
49
break ;
55
50
default :
56
51
throw new NotSupportedException (
57
52
$ "Deserializing a member of type { member . GetType ( ) } is not supported.") ;
58
53
}
59
54
}
55
+ _deserializedProxy = proxy ;
60
56
}
61
57
else
62
58
{
63
59
// Base type has a custom serialization, we need to call the proxy deserialization for deserializing
64
60
// base type members too.
65
- var proxyType = _proxyFactoryInfo . CreateProxyFactory ( ) . GetFieldInterceptionProxy ( null ) . GetType ( ) ;
61
+ var proxyType = proxy . GetType ( ) ;
66
62
var deserializationConstructor = proxyType . GetConstructor (
67
63
BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ,
68
64
null ,
@@ -95,8 +91,6 @@ public void GetBaseData(SerializationInfo info, StreamingContext context, object
95
91
info . AddValue ( HasAdditionalDataName , true ) ;
96
92
97
93
var members = FormatterServices . GetSerializableMembers ( proxyBaseType , context ) ;
98
- info . AddValue ( AdditionalMemberName , members ) ;
99
-
100
94
foreach ( var member in members )
101
95
{
102
96
switch ( member )
0 commit comments