示例#1
0
        private FieldInterceptorObjectReference(SerializationInfo info, StreamingContext context)
        {
            _proxyFactoryInfo = info.GetValue <NHibernateProxyFactoryInfo>(nameof(_proxyFactoryInfo));
            _fieldInterceptor = info.GetValue <IFieldInterceptor>(nameof(_fieldInterceptor));

            if (info.GetBoolean(HasAdditionalDataName))
            {
                _deserializedProxy = _proxyFactoryInfo.CreateProxyFactory().GetFieldInterceptionProxy(null);

                var additionalMembers = info.GetValue <MemberInfo[]>(AdditionalMemberName);
                if (additionalMembers == null)
                {
                    return;
                }

                foreach (var member in additionalMembers)
                {
                    switch (member)
                    {
                    case FieldInfo field:
                        field.SetValue(
                            _deserializedProxy,
                            info.GetValue(GetAdditionalMemberName(field), field.FieldType));
                        break;

                    case PropertyInfo property:
                        property.SetValue(
                            _deserializedProxy,
                            info.GetValue(GetAdditionalMemberName(property), property.PropertyType));
                        break;

                    default:
                        throw new NotSupportedException(
                                  $"Deserializing a member of type {member.GetType()} is not supported.");
                    }
                }
            }
            else
            {
                // Base type has a custom serialization, we need to call the proxy deserialization for deserializing
                // base type members too.
                var proxyType = _proxyFactoryInfo.CreateProxyFactory().GetFieldInterceptionProxy(null).GetType();
                var deserializationConstructor = proxyType.GetConstructor(
                    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
                    null,
                    new[] { typeof(SerializationInfo), typeof(StreamingContext) },
                    null);
                _deserializedProxy = deserializationConstructor.Invoke(new object[] { info, context });
            }
            ((IFieldInterceptorAccessor)_deserializedProxy).FieldInterceptor = _fieldInterceptor;
        }
示例#2
0
        public object GetRealObject(StreamingContext context)
        {
            var proxy = _proxyFactoryInfo.CreateProxyFactory().GetProxy(_identifier, null);

            if (_implementation != null)
            {
                proxy.HibernateLazyInitializer.SetImplementation(_implementation);
            }

            return(proxy);
        }
 public object GetRealObject(StreamingContext context)
 {
     return(_proxyFactoryInfo.CreateProxyFactory().GetProxy(_identifier, null));
 }