private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
        {
            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                _isSi = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _isSi = true;
            }

            if (_isSi)
            {
                InitSiRead();
            }
            else
            {
                InitMemberInfo();
            }
        }
        /// <summary>
        /// Get the serialization surrogate for a type, if any, else return null.
        /// </summary>
        /// <param name="type">The type to check for surrogate.</param>
        /// <returns>
        /// Returns the associated surrogate, if any, else null.
        /// </returns>
        protected ISerializationSurrogate GetSurrogateFor(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (surrogateSelector == null)
            {
                return(null);
            }

            ISerializationSurrogate surrogate;

            if (!surrogatesByType.TryGetValue(type, out surrogate))
            {
                ISurrogateSelector selectorFoundInChain;

                surrogate = surrogateSelector.GetSurrogate(type, context, out selectorFoundInChain);

                surrogatesByType[type] = surrogate;
            }

            return(surrogate);
        }
Exemple #3
0
        public virtual ISerializationSurrogate GetSurrogate
            (Type type, StreamingContext context,
            out ISurrogateSelector selector)
        {
            // Validate the type parameter.
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            // Look for a surrogate in this selector.
            ISerializationSurrogate surrogate;

            surrogate = (table[new KeyInfo(type, context)]
                         as ISerializationSurrogate);
            if (surrogate != null)
            {
                selector = this;
                return(surrogate);
            }

            // Look for a surrogate in the next selector.
            if (nextSelector != null)
            {
                return(nextSelector.GetSurrogate
                           (type, context, out selector));
            }

            // We were unable to find a surrogate.
            selector = this;
            return(null);
        }
Exemple #4
0
 private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, string assemblyName)
 {
     if (objectType.IsArray)
     {
         this.arrayElemObjectInfo = Create(objectType.GetElementType(), surrogateSelector, context, this.objectManager, this.serObjectInfoInit, this.formatterConverter, assemblyName);
         this.typeAttributeInfo   = this.GetTypeAttributeInfo();
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!(objectType == Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.si = new SerializationInfo(objectType, this.formatterConverter);
             this.InitSiRead(assemblyName);
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
        /// <summary>
        /// Returns the surrogate for a particular type.
        /// </summary>
        ///
        /// <returns>The surrogate for a particular type.</returns>
        /// <param name="type">The <see cref="T:System.Type"/> for which the surrogate is
        /// requested.</param>
        /// <param name="context">The streaming context.</param>
        /// <param name="selector">The surrogate to use.</param>
        /// <exception cref="T:System.ArgumentNullException">The
        /// <paramref name="type"/>parameter is null.</exception>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the
        /// required permission.</exception>
        /// <PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/></PermissionSet>
        public virtual ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type is null.");
            }

            Dictionary <StreamingContextStates, ISerializationSurrogate> surrogates;
            ISerializationSurrogate serializationSurrogate = null;

            if (_surrogates.TryGetValue(type, out surrogates))
            {
                surrogates.TryGetValue(context.State, out serializationSurrogate);
            }

            if (serializationSurrogate != null)
            {
                selector = this;
                return(serializationSurrogate);
            }

            else
            {
                if (_nextSelector != null)
                {
                    return(_nextSelector.GetSurrogate(type, context, out selector));
                }

                selector = null;
                return(null);
            }
        }
Exemple #6
0
        bool CheckIfTypeSerializableForSharedTypeMode(Type memberType)
        {
            Fx.Assert(surrogateSelector != null, "Method should not be called when surrogateSelector is null.");
            ISurrogateSelector surrogateSelectorNotUsed;

            return(surrogateSelector.GetSurrogate(memberType, streamingContext, out surrogateSelectorNotUsed) != null);
        }
Exemple #7
0
        public virtual ISerializationSurrogate GetSurrogate(Type type,
                                                            StreamingContext context, out ISurrogateSelector selector)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type is null.");
            }

            // Check this selector, and if the surrogate is not found,
            // check the chained selectors

            string key = type.FullName + "#" + context.ToString();
            ISerializationSurrogate surrogate = (ISerializationSurrogate)Surrogates [key];

            if (surrogate != null)
            {
                selector = this;
                return(surrogate);
            }

            if (nextSelector != null)
            {
                return(nextSelector.GetSurrogate(type, context, out selector));
            }
            else
            {
                selector = null;
                return(null);
            }
        }
            public ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
            {
                var surrogate = underlyingSelector.GetSurrogate(type, context, out selector);

                writer.WriteLine("{0} -> {1}", type, surrogate == null ? "null" : surrogate.ToString());
                return(surrogate);
            }
 private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
 {
     if (objectType.IsArray)
     {
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!object.ReferenceEquals(objectType, Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.InitSiRead();
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
Exemple #10
0
        private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
        {
            if (objectType.IsArray)
            {
                this.InitNoMembers();
                return;
            }
            ISurrogateSelector surrogateSelector2 = null;

            if (surrogateSelector != null)
            {
                this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelector2);
            }
            if (this.serializationSurrogate != null)
            {
                this.isSi = true;
            }
            else if (objectType != Converter.typeofObject && Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                this.isSi = true;
            }
            if (this.isSi)
            {
                this.InitSiRead();
                return;
            }
            this.InitMemberInfo();
        }
Exemple #11
0
        private void SerializeObject(object currentObject, long currentObjectId)
        {
            bool needsSerializationInfo = false;
            ISurrogateSelector      selector;
            ISerializationSurrogate surrogate = null;

            if (_surrogateSelector != null)
            {
                surrogate = _surrogateSelector.GetSurrogate(
                    currentObject.GetType(),
                    _context,
                    out selector);
            }
            if (currentObject is ISerializable || surrogate != null)
            {
                needsSerializationInfo = true;
            }

#if NET_2_0 && !TARGET_JVM
            _manager.RegisterObject(currentObject);
#endif

            if (needsSerializationInfo)
            {
                SerializeISerializableObject(currentObject, currentObjectId, surrogate);
            }
            else
            {
                if (!currentObject.GetType().IsSerializable)
                {
                    throw new SerializationException(String.Format("Type {0} in assembly {1} is not marked as serializable.", currentObject.GetType(), currentObject.GetType().Assembly.FullName));
                }
                SerializeSimpleObject(currentObject, currentObjectId);
            }
        }
Exemple #12
0
        private void RegisterObjectInternal(object obj, ObjectRecord record)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (record.IsRegistered)
            {
                if (record.OriginalObject != obj)
                {
                    throw new SerializationException("An object with Id " + record.ObjectID + " has already been registered");
                }
                else
                {
                    return;
                }
            }

            record.ObjectInstance = obj;
            record.OriginalObject = obj;

            if (obj is IObjectReference)
            {
                record.Status = ObjectRecordStatus.ReferenceUnsolved;
            }
            else
            {
                record.Status = ObjectRecordStatus.ReferenceSolved;
            }

            if (_selector != null)
            {
                record.Surrogate = _selector.GetSurrogate(
                    obj.GetType(), _context, out record.SurrogateSelector);
                if (record.Surrogate != null)
                {
                    record.Status = ObjectRecordStatus.ReferenceUnsolved;
                }
            }

            record.DoFixups(true, this, false);
            record.DoFixups(false, this, false);
            _registeredObjectsCount++;

            // Adds the object to the chain of registered objects. This chain
            // is needed to be able to to perform the final fixups in the right order

            if (_objectRecordChain == null)
            {
                _objectRecordChain = record;
                _lastObjectRecord  = record;
            }
            else
            {
                _lastObjectRecord.Next = record;
                _lastObjectRecord      = record;
            }
        }
Exemple #13
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                Assembly mscorlibAsm                         = Assembly.Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
                var      FormatterServicesRef                = mscorlibAsm.GetType("System.Runtime.Serialization.FormatterServices");
                var      unsafeTypeForwardersIsEnabled       = FormatterServicesRef.GetMethod("UnsafeTypeForwardersIsEnabled", BindingFlags.Static | BindingFlags.NonPublic);
                var      unsafeTypeForwardersIsEnabledResult = (bool)unsafeTypeForwardersIsEnabled.Invoke(null, new object[] { });
                si = new SerializationInfo(objectType, converter, !unsafeTypeForwardersIsEnabledResult);

                //si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Exemple #14
0
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 1 ", obj);
            this.context           = context;
            this.obj               = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
            {
                objectType = Converter.typeofMarshalByRefObject;
            }
            else
            {
                objectType = obj.GetType();
            }

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            SerTrace.Log(this, objectInfoId, " Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                {
                    serializationSurrogate.GetObjectData(obj, si, context);
                }
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable)
                {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NonSerType"),
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 4 ISerializable " + objectType);
                InitSiWrite();
            }
            else
            {
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
Exemple #15
0
        private ISerializationSurrogate getSerializationSurrogate(Type type, out ISurrogateSelector selector, ISurrogateSelector startingSelector)
        {
            System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != startingSelector, "The 'startingSelector' argument cannot be null.");

            ISerializationSurrogate serializationSurrogate =
                startingSelector.GetSurrogate(type, this.context, out selector);

            if (null == serializationSurrogate && typeof(ISerializable).IsAssignableFrom(type))
            {
                serializationSurrogate = startingSelector.GetSurrogate(typeof(ISerializable), this.context, out selector);
            }

            if (null == serializationSurrogate)
            {
                serializationSurrogate = startingSelector.GetSurrogate(typeof(object), this.context, out selector);
            }

            return(serializationSurrogate);
        }
Exemple #16
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo)
        {
            InternalST.Soap(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType                = objectType;
            this.context                   = context;
            this.serObjectInfoInit         = serObjectInfoInit;
            this.parentMemberAttributeInfo = attributeInfo;
            this.surrogateSelector         = surrogateSelector;
            this.converter                 = converter;

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
                typeAttributeInfo   = GetTypeAttributeInfo();
                InitNoMembers();
                return;
            }

            typeAttributeInfo = GetTypeAttributeInfo();

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                isSi = true;
            }

            if (isSi)
            {
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache();
                cache.fullTypeName   = si.FullTypeName;
                cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            InternalST.Soap(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Exemple #17
0
        public static void CheckSerializable(Type type, ISurrogateSelector selector, StreamingContext context)
        {
            if (!type.IsSerializable && !type.IsInterface)
            {
                if (selector != null && selector.GetSurrogate(type, context, out selector) != null)
                {
                    return;
                }

                throw new SerializationException("Type " + type + " is not marked as Serializable.");
            }
        }
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo, ObjectWriter objectWriter)
 {
     this.context                   = context;
     this.obj                       = obj;
     this.serObjectInfoInit         = serObjectInfoInit;
     this.parentMemberAttributeInfo = attributeInfo;
     this.surrogateSelector         = surrogateSelector;
     this.converter                 = converter;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.arrayElemObjectInfo = Serialize(this.objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
         this.typeAttributeInfo   = this.GetTypeAttributeInfo();
         this.isArray             = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite(objectWriter);
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NonSerType"), new object[] { this.objectType.FullName, this.objectType.Module.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter);
             ((ISerializable)obj).GetObjectData(this.si, context);
             this.InitSiWrite(objectWriter);
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
        internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            this.context           = context;
            this.obj               = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            if (RemotingServices.IsTransparentProxy(obj))
            {
                this.objectType = Converter.typeofMarshalByRefObject;
            }
            else
            {
                this.objectType = obj.GetType();
            }
            if (this.objectType.IsArray)
            {
                this.isArray = true;
                this.InitNoMembers();
                return;
            }
            this.InvokeSerializationBinder(binder);
            objectWriter.ObjectManager.RegisterObject(obj);
            ISurrogateSelector surrogateSelector2;

            if (surrogateSelector != null && (this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out surrogateSelector2)) != null)
            {
                this.si = new SerializationInfo(this.objectType, converter);
                if (!this.objectType.IsPrimitive)
                {
                    this.serializationSurrogate.GetObjectData(obj, this.si, context);
                }
                this.InitSiWrite();
                return;
            }
            if (!(obj is ISerializable))
            {
                this.InitMemberInfo();
                WriteObjectInfo.CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
                return;
            }
            if (!this.objectType.IsSerializable)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[]
                {
                    this.objectType.FullName,
                    this.objectType.Assembly.FullName
                }));
            }
            this.si = new SerializationInfo(this.objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
            ((ISerializable)obj).GetObjectData(this.si, context);
            this.InitSiWrite();
            WriteObjectInfo.CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
        }
Exemple #20
0
        public ISerializationSurrogate GetSurrogate(Type type, StreamingContext ctx, out ISurrogateSelector selector)
        {
            selector = null;

            DBG.Info(DBG.SC, "CSS: GetSurrogate(" + type + ")");
            if (type.IsCOMObject)
            {
                selector = this;
                return(this);
            }

            return(_deleg.GetSurrogate(type, ctx, out selector));
        }
Exemple #21
0
        // Write Constructor used for array types or null members
        // [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                si    = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Exemple #22
0
 public ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
 {
     selector = this;
     if (!IsAllowedType(type))
     {
         throw new SecurityException("Unknown type: " + type.FullName);
     }
     if (type == typeof(Vector2))
     {
         return(new Vector2Surrogate());
     }
     if (type == typeof(Vector3))
     {
         return(new Vector3Surrogate());
     }
     if (type == typeof(Vector4))
     {
         return(new Vector4Surrogate());
     }
     if (type == typeof(Quaternion))
     {
         return(new QuaternionSurrogate());
     }
     if (type == typeof(Color))
     {
         return(new ColorSurrogate());
     }
     if (type == typeof(Color32))
     {
         return(new Color32Surrogate());
     }
     if (type == typeof(GameObject))
     {
         return(new GameObjectSurrogate());
     }
     if (type == typeof(Transform))
     {
         return(new TransformSurrogate());
     }
     if (type.IsSubclassOf(typeof(Object)))
     {
         return(new ObjectSurrogate());
     }
     selector = null;
     if (_next != null)
     {
         return(_next.GetSurrogate(type, context, out selector));
     }
     return(null);
 }
        /// <inheritdoc/>
        public ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
        {
            if (typeof(GrainReference).IsAssignableFrom(type))
            {
                selector = this;
                return(_surrogate);
            }

            if (_chainedSelector is object)
            {
                return(_chainedSelector.GetSurrogate(type, context, out selector));
            }

            selector = null;
            return(null);
        }
Exemple #24
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                isSi = true;
            }

            if (isSi)
            {
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache();
                cache.fullTypeName   = si.FullTypeName;
                cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
 public ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
 {
     if (SimpleUnityStructureSurrogate.IsSpeciallySerialized(type))
     {
         selector = this;
         return(this);
     }
     else if (_nextSelector != null)
     {
         return(_nextSelector.GetSurrogate(type, context, out selector));
     }
     else
     {
         selector = null;
         return(null);
     }
 }
Exemple #26
0
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationObjectInfo serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
 {
     _context           = context;
     _obj               = obj;
     _serObjectInfoInit = serObjectInfoInit;
     _objectType        = obj.GetType();
     if (_objectType.IsArray)
     {
         _isArray = true;
         InitNoMembers();
     }
     else if (_objectType.IsSerializable)
     {
         InvokeSerializationBinder(binder);
         objectWriter.ObjectManager.RegisterObject(obj);
         if (surrogateSelector != null && (_serializationSurrogate = surrogateSelector.GetSurrogate(_objectType, context, out _)) != null)
         {
             _si = new SerializationInfo(_objectType, converter);
             if (!_objectType.IsPrimitive)
             {
                 _serializationSurrogate.GetObjectData(obj, _si, context);
             }
             InitSiWrite();
         }
         else if (obj is ISerializable serializable)
         {
             if (!_objectType.IsSerializable)
             {
                 throw new SerializationException(RemotingResources.NotMarkedForSerialization.Format(_objectType.FullName, _objectType.Assembly.FullName));
             }
             _si = new SerializationInfo(_objectType, converter);
             serializable.GetObjectData(_si, context);
             InitSiWrite();
             //CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
         }
         else
         {
             InitMemberInfo();
             //CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
         }
     }
     else
     {
         throw new SerializationException(RemotingResources.NotMarkedForSerialization.Format(_objectType.FullName, _objectType.Assembly.FullName));
     }
 }
 internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo)
 {
     this.objectType                = objectType;
     this.context                   = context;
     this.serObjectInfoInit         = serObjectInfoInit;
     this.parentMemberAttributeInfo = attributeInfo;
     this.surrogateSelector         = surrogateSelector;
     this.converter                 = converter;
     if (objectType.IsArray)
     {
         this.arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
         this.typeAttributeInfo   = this.GetTypeAttributeInfo();
         this.InitNoMembers();
     }
     else
     {
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!(objectType == Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.si    = new SerializationInfo(objectType, converter);
             this.cache = new SerObjectInfoCache();
             this.cache.fullTypeName   = this.si.FullTypeName;
             this.cache.assemblyString = this.si.AssemblyName;
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
Exemple #28
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            _objectType        = objectType;
            _context           = context;
            _serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                _si    = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                _isSi  = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _si    = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                _isSi = true;
            }

            if (!_isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
            }
        }
Exemple #29
0
        private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, String assemblyName)
        {
            InternalST.Soap(this, objectInfoId, " ", objectType, " InitReadConstructor Entry ", objectType);

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Create(objectType.GetElementType(), surrogateSelector, context, objectManager, serObjectInfoInit, formatterConverter, assemblyName);
                typeAttributeInfo   = GetTypeAttributeInfo();
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                isSi = true;
            }

            if (isSi)
            {
                si = new SerializationInfo(objectType, formatterConverter);
                InitSiRead(assemblyName);
            }
            else
            {
                InitMemberInfo();
            }
            InternalST.Soap(this, objectInfoId, " ", objectType, " InitReadConstructor Exit ", isSi);
        }
Exemple #30
0
 public ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
 {
     if (SerializedTypes.Any(t => t.IsAssignableFrom(type)))
     {
         selector = this;
         return(new FieldSerializationSurrogate());
     }
     else
     {
         if (_next == null)
         {
             selector = null;
             return(null);
         }
         else
         {
             return(_next.GetSurrogate(type, context, out selector));
         }
     }
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            SerTrace.Log( this, objectInfoId," Constructor 1 ",obj);
            this.context = context;
            this.obj = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

#if  FEATURE_REMOTING        
            if (RemotingServices.IsTransparentProxy(obj))
                objectType = Converter.typeofMarshalByRefObject;
            else
#endif
                objectType = obj.GetType();

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            SerTrace.Log( this, objectInfoId," Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                    serializationSurrogate.GetObjectData(obj, si, context);
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable) {
                    throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType",
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
#if FEATURE_SERIALIZATION
                ((ISerializable)obj).GetObjectData(si, context);
#endif
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 4 ISerializable "+objectType);
                InitSiWrite();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }
            else
            {
                SerTrace.Log(this, objectInfoId," Constructor 1 trace 5");
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }
        }
Exemple #32
0
		public static void CheckSerializable (Type type, ISurrogateSelector selector, StreamingContext context)
		{
			if (!type.IsSerializable && !type.IsInterface) 
			{
				if (selector != null && selector.GetSurrogate (type, context, out selector) != null)
					return;

				throw new SerializationException ("Type " + type + " is not marked as Serializable.");
			}
		}
 private static ISerializationSurrogate GetSurrogate(Type type, ISurrogateSelector surrogateSelector, StreamingContext context)
 {
     ISurrogateSelector selector;
     return surrogateSelector.GetSurrogate(type, context, out selector);
 }
Exemple #34
0
        // Write constructor
        internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            _context = context;
            _obj = obj;
            _serObjectInfoInit = serObjectInfoInit;
            _objectType = obj.GetType();

            if (_objectType.IsArray)
            {
                _isArray = true;
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);
            objectWriter.ObjectManager.RegisterObject(obj);

            ISurrogateSelector surrogateSelectorTemp;
            if (surrogateSelector != null && (_serializationSurrogate = surrogateSelector.GetSurrogate(_objectType, context, out surrogateSelectorTemp)) != null)
            {
                _si = new SerializationInfo(_objectType, converter);
                if (!_objectType.IsPrimitive)
                {
                    _serializationSurrogate.GetObjectData(obj, _si, context);
                }
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!_objectType.IsSerializable)
                {
                    throw new SerializationException(SR.Format(SR.Serialization_NonSerType, _objectType.FullName, _objectType.Assembly.FullName));
                }
                _si = new SerializationInfo(_objectType, converter);
                ((ISerializable)obj).GetObjectData(_si, context);
                InitSiWrite();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
            else
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
        }
Exemple #35
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo)
        {

            InternalST.Soap( this, objectInfoId," Constructor 2 ",objectType);     

            this.objectType = objectType;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;
            this.parentMemberAttributeInfo = attributeInfo;         
            this.surrogateSelector = surrogateSelector;
            this.converter = converter;

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
                typeAttributeInfo = GetTypeAttributeInfo();
                InitNoMembers();
                return;         
            }

            typeAttributeInfo = GetTypeAttributeInfo();

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
                isSi = true;

            if (isSi)
            {
                si = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache();
                cache.fullTypeName = si.FullTypeName;
                cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            InternalST.Soap( this,objectInfoId," ", objectType," InitSerialize Exit ",isSi);       
        }
 internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
 {
     this.objectType = objectType;
     this.context = context;
     this.serObjectInfoInit = serObjectInfoInit;
     if (objectType.IsArray)
     {
         this.InitNoMembers();
     }
     else
     {
         this.InvokeSerializationBinder(binder);
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.si = new SerializationInfo(objectType, converter);
             this.cache = new SerObjectInfoCache(objectType);
             this.isSi = true;
         }
         else if (!object.ReferenceEquals(objectType, Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
             this.cache = new SerObjectInfoCache(objectType);
             CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString);
             this.isSi = true;
         }
         if (!this.isSi)
         {
             this.InitMemberInfo();
             CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString);
         }
     }
 }
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
 {
     this.context = context;
     this.obj = obj;
     this.serObjectInfoInit = serObjectInfoInit;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.isArray = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.InvokeSerializationBinder(binder);
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite();
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { this.objectType.FullName, this.objectType.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
             ((ISerializable) obj).GetObjectData(this.si, context);
             this.InitSiWrite();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
         else
         {
             this.InitMemberInfo();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
     }
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {

            SerTrace.Log( this, objectInfoId," Constructor 2 ",objectType);

            this.objectType = objectType;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log( this,objectInfoId," ", objectType," InitSerialize Exit ",isSi);
        }
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo, ObjectWriter objectWriter)
 {
     this.context = context;
     this.obj = obj;
     this.serObjectInfoInit = serObjectInfoInit;
     this.parentMemberAttributeInfo = attributeInfo;
     this.surrogateSelector = surrogateSelector;
     this.converter = converter;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.arrayElemObjectInfo = Serialize(this.objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         this.isArray = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite(objectWriter);
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NonSerType"), new object[] { this.objectType.FullName, this.objectType.Module.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter);
             ((ISerializable) obj).GetObjectData(this.si, context);
             this.InitSiWrite(objectWriter);
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
        {

            SerTrace.Log( this, objectInfoId," Constructor 2 ",objectType);

            this.objectType = objectType;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
                isSi = true;

            if (isSi)
            {
		    si = new SerializationInfo(objectType, converter);
		    cache = new SerObjectInfoCache();
		    cache.fullTypeName = si.FullTypeName;
		    cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            SerTrace.Log( this,objectInfoId," ", objectType," InitSerialize Exit ",isSi);
        }
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
        {
            SerTrace.Log( this, objectInfoId," Constructor 1 ",obj);
            this.context = context;
            this.obj = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
                objectType = Converter.typeofMarshalByRefObject;
            else
                objectType = obj.GetType();

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            SerTrace.Log( this, objectInfoId," Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                    serializationSurrogate.GetObjectData(obj, si, context);
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable) {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NonSerType"),
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 4 ISerializable "+objectType);
                InitSiWrite();
            }
            else
            {
                SerTrace.Log(this, objectInfoId," Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
 private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, string assemblyName)
 {
     if (objectType.IsArray)
     {
         this.arrayElemObjectInfo = Create(objectType.GetElementType(), surrogateSelector, context, this.objectManager, this.serObjectInfoInit, this.formatterConverter, assemblyName);
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!(objectType == Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.si = new SerializationInfo(objectType, this.formatterConverter);
             this.InitSiRead(assemblyName);
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
Exemple #43
0
        private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, String assemblyName)
        {
            InternalST.Soap( this,objectInfoId," ", objectType," InitReadConstructor Entry ",objectType);

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Create(objectType.GetElementType(), surrogateSelector, context, objectManager, serObjectInfoInit, formatterConverter, assemblyName);
                typeAttributeInfo = GetTypeAttributeInfo();
                InitNoMembers();
                return;         
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
                isSi = true;

            if (isSi)
            {
                si = new SerializationInfo(objectType, formatterConverter);
                InitSiRead(assemblyName);
            }
            else
            {
                InitMemberInfo();
            }
            InternalST.Soap( this,objectInfoId," ", objectType," InitReadConstructor Exit ",isSi);     
        }
        [System.Security.SecurityCritical]  // auto-generated
        private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
        {
            SerTrace.Log( this,objectInfoId," ", objectType," InitReadConstructor Entry ",objectType);

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
                isSi = true;

            if (isSi)
            {
                InitSiRead();
            }
            else
            {
                InitMemberInfo();
            }
            SerTrace.Log( this,objectInfoId," ", objectType," InitReadConstructor Exit ",isSi);
        }
 internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo)
 {
     this.objectType = objectType;
     this.context = context;
     this.serObjectInfoInit = serObjectInfoInit;
     this.parentMemberAttributeInfo = attributeInfo;
     this.surrogateSelector = surrogateSelector;
     this.converter = converter;
     if (objectType.IsArray)
     {
         this.arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         this.InitNoMembers();
     }
     else
     {
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!(objectType == Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.si = new SerializationInfo(objectType, converter);
             this.cache = new SerObjectInfoCache();
             this.cache.fullTypeName = this.si.FullTypeName;
             this.cache.assemblyString = this.si.AssemblyName;
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
Exemple #46
0
 static ISerializationSurrogate GetSurrogate(Type type, ISurrogateSelector surrogateSelector, StreamingContext context)
 {
     ISurrogateSelector surrogateSelectorNotUsed;
     return surrogateSelector.GetSurrogate(type, context, out surrogateSelectorNotUsed);
 }
Exemple #47
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            _objectType = objectType;
            _context = context;
            _serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;
            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                _si = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                _isSi = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _si = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                _isSi = true;
            }

            if (!_isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
            }
        }
Exemple #48
0
        private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
        {
            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;
            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                _isSi = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _isSi = true;
            }

            if (_isSi)
            {
                InitSiRead();
            }
            else
            {
                InitMemberInfo();
            }
        }
		private ISerializationSurrogate getSerializationSurrogate(Type type, out ISurrogateSelector selector, ISurrogateSelector startingSelector)
		{
			System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");
			System.Diagnostics.Debug.Assert(null != startingSelector, "The 'startingSelector' argument cannot be null.");

			ISerializationSurrogate serializationSurrogate =
				startingSelector.GetSurrogate(type, this.context, out selector);

			if (null == serializationSurrogate && typeof(ISerializable).IsAssignableFrom(type))
				serializationSurrogate = startingSelector.GetSurrogate(typeof(ISerializable), this.context, out selector);

			if (null == serializationSurrogate)
				serializationSurrogate = startingSelector.GetSurrogate(typeof(object), this.context, out selector);

			return serializationSurrogate;
		}
Exemple #50
0
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo)
        {
            InternalST.Soap( this, objectInfoId," Constructor 1 ",obj);        
            this.context = context;
            this.obj = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            this.parentMemberAttributeInfo = attributeInfo;
            this.surrogateSelector = surrogateSelector;
            this.converter = converter;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
                objectType = Converter.typeofMarshalByRefObject;
            else
                objectType = obj.GetType();

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
                typeAttributeInfo = GetTypeAttributeInfo();
                isArray = true;
                InitNoMembers();
                return;
            }

            InternalST.Soap( this, objectInfoId," Constructor 1 trace 2");

            typeAttributeInfo = GetTypeAttributeInfo();

            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                InternalST.Soap( this, objectInfoId," Constructor 1 trace 3");         
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                    serializationSurrogate.GetObjectData(obj, si, context);
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable)
                {
                    throw new SerializationException(String.Format(SoapUtil.GetResourceString("Serialization_NonSerType"), 
                                                                   objectType.FullName, objectType.Module.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                InternalST.Soap( this, objectInfoId," Constructor 1 trace 4 ISerializable "+objectType);                       
                InitSiWrite();
            }
            else
            {
                InternalST.Soap(this, objectInfoId," Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
 private void InitReadConstructor(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context)
 {
     if (objectType.IsArray)
     {
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector = null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.isSi = true;
         }
         else if (!object.ReferenceEquals(objectType, Converter.typeofObject) && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.isSi = true;
         }
         if (this.isSi)
         {
             this.InitSiRead();
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }