Beispiel #1
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void Init(Type objectType, String[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 5 ", objectType);
            this.objectType         = objectType;
            this.objectManager      = objectManager;
            this.wireMemberNames    = memberNames;
            this.wireMemberTypes    = memberTypes;
            this.context            = context;
            this.serObjectInfoInit  = serObjectInfoInit;
            this.formatterConverter = converter;
            this.bSimpleAssembly    = bSimpleAssembly;
            if (memberNames != null)
            {
                isNamed = true;
            }
            if (memberTypes != null)
            {
                isTyped = true;
            }

            if ((object)objectType != null)
            {
                InitReadConstructor(objectType, surrogateSelector, context);
            }
        }
Beispiel #2
0
        private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            ReadObjectInfo roi = new ReadObjectInfo();

            roi.objectInfoId = Interlocked.Increment(ref readObjectInfoCounter);
            return(roi);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 3 ", objectType);

            this.objectType         = objectType;
            this.objectManager      = objectManager;
            this.context            = context;
            this.serObjectInfoInit  = serObjectInfoInit;
            this.formatterConverter = converter;
            this.bSimpleAssembly    = bSimpleAssembly;

            InitReadConstructor(objectType, surrogateSelector, context);
        }
Beispiel #5
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo objectInfo = null;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                objectInfo = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                objectInfo.InternalInit();
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo from pool");
            }
            else
            {
                objectInfo = new WriteObjectInfo();
                objectInfo.objectInfoId = serObjectInfoInit.objectInfoIdCount++;
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo new not from pool");
            }

            return(objectInfo);
        }
Beispiel #6
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static ReadObjectInfo Create(Type objectType, String[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            ReadObjectInfo soi = GetObjectInfo(serObjectInfoInit);

            soi.Init(objectType, memberNames, memberTypes, surrogateSelector, context, objectManager, serObjectInfoInit, converter, bSimpleAssembly);
            return(soi);
        }
Beispiel #7
0
 private static void PutObjectInfo(SerObjectInfoInit serObjectInfoInit, WriteObjectInfo objectInfo)
 {
     serObjectInfoInit.oiPool.Push(objectInfo);
     //SerTrace.Log( "PutObjectInfo",objectInfo.objectInfoId," PutObjectInfo to pool");
 }
Beispiel #8
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static WriteObjectInfo Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            WriteObjectInfo soi = GetObjectInfo(serObjectInfoInit);

            soi.InitSerialize(objectType, surrogateSelector, context, serObjectInfoInit, converter, binder);
            return(soi);
        }
Beispiel #9
0
        [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));
                }
                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());
//#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);
            }
        }