Esempio n. 1
0
        // Read Constructor
        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 (objectType != null)
            {
                InitReadConstructor(objectType, surrogateSelector, context);
            }
        }
Esempio n. 2
0
        public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
#endif
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Contract.EndContractBlock();

            objectType     = type;
            m_fullTypeName = type.FullName;
            m_assemName    = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data    = new Object[defaultSize];
            m_types   = new Type[defaultSize];

            m_converter = converter;

#if FEATURE_SERIALIZATION
            this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
#endif
        }
Esempio n. 3
0
        public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Contract.EndContractBlock();

            objectType = type;
            m_fullTypeName = type.FullName;
            m_assemName = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data = new Object[defaultSize];
            m_types = new Type[defaultSize];

            m_nameToIndex = new Dictionary<string, int>();

            m_converter = converter;

            this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
        }
Esempio n. 4
0
        public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            if (requireSameTokenInPartialTrust)
            {
                throw new NotSupportedException("Cannot require token trust");
            }

            objectType     = type;
            m_fullTypeName = type.FullName;

            m_members = new string[defaultSize];
            m_data    = new object[defaultSize];
            m_types   = new Type[defaultSize];

            m_nameToIndex = new Dictionary <string, int>();

            m_converter = converter;
        }
Esempio n. 5
0
        public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (converter == null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            Contract.EndContractBlock();

            objectType     = type;
            m_fullTypeName = type.FullName;
            m_assemName    = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data    = new Object[defaultSize];
            m_types   = new Type[defaultSize];

            m_nameToIndex = new Dictionary <string, int>();

            m_converter = converter;

            this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
        }
Esempio n. 6
0
		/* used by the runtime */
		private SerializationInfo (Type type)
		{
			assemblyName = type.Assembly.FullName;
			fullTypeName = type.FullName;
			converter = new FormatterConverter ();
			objectType = type;
		}
Esempio n. 7
0
        public SerializationInfo(Type type, IFormatterConverter converter)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Contract.EndContractBlock();

            objectType     = type;
            m_fullTypeName = type.FullName;
            m_assemName    = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data    = new Object[defaultSize];
            m_types   = new Type[defaultSize];

            m_converter = converter;

            m_currMember = 0;
        }
Esempio n. 8
0
        protected SerializationInfo(Type objType, IFormatterConverter converter)
        {
            Type      = objType;
            Converter = converter;

            // create an instance of the object to get missing values from the field initializers.
            object instance = STDFFormatterServices.GetUninitializedObject(Type);

            FieldInfo[] fields = STDFFormatterServices.GetSerializeableFields(Type);

            Info = new SerializationInfoEntry[fields.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                var    field          = fields[i];
                object value          = field.GetValue(instance);
                string itemCountField = (field.GetCustomAttribute <STDFAttribute>() ??
                                         field.GetCustomAttribute <STDFOptionalAttribute>())?.ItemCountProperty;
                var entry = new SerializationInfoEntry()
                {
                    Index          = i,
                    Name           = field.Name,
                    Type           = field.FieldType,
                    IsOptional     = field.GetCustomAttribute <STDFOptionalAttribute>() != null,
                    IsSet          = false,
                    ItemCountIndex = Array.FindIndex(fields, x => x.Name == itemCountField),
                    Value          = value,
                    MissingValue   = value
                };
                Info[i] = entry;
            }
        }
        public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
#endif
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Contract.EndContractBlock();

            objectType = type;
            m_fullTypeName = type.FullName;
            m_assemName = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data = new Object[defaultSize];
            m_types = new Type[defaultSize];

            m_converter = converter;

#if FEATURE_SERIALIZATION
            this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
#endif
        }
    public SerializationInfo(Type type, IFormatterConverter converter)
    {
      if (null == type)
      {
        throw new ArgumentNullException("type");
      }

      if (converter == null)
      {
        throw new ArgumentNullException("converter");
      }


      m_fullTypeName = type.FullName;
      m_assemName = type.Module.Assembly.FullName;
      Debug.Assert(m_fullTypeName != null, "[SerializationInfo.ctor]m_fullTypeName!=null");
      Debug.Assert(m_assemName != null, "[SerializationInfo.ctor]m_assemName!=null");

      m_members = new String[defaultSize];
      m_data = new Object[defaultSize];
      m_types = new Type[defaultSize];

      m_converter = converter;

      m_currMember = 0;

    }
Esempio n. 11
0
        public SerializationInfo(Type type, IFormatterConverter converter)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }


            m_fullTypeName = type.FullName;
            m_assemName    = type.Module.Assembly.FullName;
            Debug.Assert(m_fullTypeName != null, "[SerializationInfo.ctor]m_fullTypeName!=null");
            Debug.Assert(m_assemName != null, "[SerializationInfo.ctor]m_assemName!=null");

            m_members = new String[defaultSize];
            m_data    = new Object[defaultSize];
            m_types   = new Type[defaultSize];

            m_converter = converter;

            m_currMember = 0;
        }
Esempio n. 12
0
 /* used by the runtime */
 private SerializationInfo(Type type)
 {
     assemblyName = type.Assembly.FullName;
     fullTypeName = type.FullName;
     converter    = new FormatterConverter();
     objectType   = type;
 }
Esempio n. 13
0
        private /*static*/ object readValue(XmlReader xmlReader, Type type, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlReader, "The 'xmlReader' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");
            System.Diagnostics.Debug.Assert(this.isSimpleType(type), "The Type type is not a simple type.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            object value = null;             // Return value
            string valueRepresentation = xmlReader.ReadString();

            if (type.IsPrimitive || typeof(System.String) == type)
            {
                value = converter.Convert(valueRepresentation, type);
            }
            else if (type.IsEnum)
            {
                value = Enum.Parse(type, valueRepresentation);
            }
            else if (typeof(System.Guid) == type)
            {
                value = new GuidConverter().ConvertFromInvariantString(valueRepresentation);
            }

            // When the value is the empty string the xml element is empty and there is not an xml end element.
            // Read the following element.
            if (xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement();
            }

            return(value);
        }
Esempio n. 14
0
        private void serializeEntry(XmlWriter xmlWriter, SerializationEntry entry, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlWriter, "The 'xmlWriter' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            if (entry.Name.Contains("+"))
            {
                string[] nameParts = entry.Name.Split(new char[] { '+' });

                xmlWriter.WriteStartElement(nameParts[1]);

                xmlWriter.WriteStartAttribute("declaringType");
                xmlWriter.WriteValue(nameParts[0]);
                xmlWriter.WriteEndAttribute();
            }
            else
            {
                xmlWriter.WriteStartElement(entry.Name);
            }

            object entryValue = entry.Value;

            if (null == entryValue)
            {
                xmlWriter.WriteStartAttribute("isNull");
                xmlWriter.WriteValue(true);
                xmlWriter.WriteEndAttribute();
            }
            else
            {
                this.serializeObject(xmlWriter, entryValue, converter);
            }

            xmlWriter.WriteEndElement();
        }
Esempio n. 15
0
 /// <summary>
 /// Static method to create and return a new SerializationInfo object for the given type.
 /// </summary>
 /// <param name="objType">Type of object to initialize the SerializationInfo object for.</param>
 /// <param name="converter">IFormatterConverter used to convert datatypes for serialization/deserialization.</param>
 /// <returns></returns>
 public static SerializationInfo Create(Type objType, IFormatterConverter converter)
 {
     if (!InfoCache.TryGetValue(objType.Name, out SerializationInfo info))
     {
         info = new SerializationInfo(objType, converter);
         InfoCache.Add(objType.Name, info);
     }
     else
     {
         if (info != null)
         {
             // for existing info object, set the isset property to false and copy the missing value
             // to the value to get ready for serialization/deserialization.
             for (int i = 0; i < info.Info.Length; i++)
             {
                 if (info.Info[i] != null)
                 {
                     info.Info[i].IsSet = false;
                     info.Info[i].Value = info.Info[i].MissingValue;
                 }
             }
         }
     }
     return(info);
 }
Esempio n. 16
0
        internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException(nameof(serWriter));
            }

            _serWriter = serWriter;

            serWriter.WriteBegin();
            long   headerId = 0;
            object obj;
            long   objectId;
            bool   isNew;

            // allocations if methodCall or methodResponse and no graph
            _idGenerator        = new ObjectIDGenerator();
            _objectQueue        = new Queue <object>();
            _formatterConverter = new FormatterConverter();
            _serObjectInfoInit  = new SerObjectInfoInit();

            _topId   = InternalGetId(graph, false, null, out isNew);
            headerId = -1;
            WriteSerializedStreamHeader(_topId, headerId);

            _objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId)) != null)
            {
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo.
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo          = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    objectInfo._assemId = GetAssemblyId(objectInfo);
                }

                objectInfo._objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            _objectManager.RaiseOnSerializedEvent();
        }
Esempio n. 17
0
        internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException(nameof(serWriter));
            }

            _serWriter = serWriter;

            serWriter.WriteBegin();
            long headerId = 0;
            object obj;
            long objectId;
            bool isNew;

            // allocations if methodCall or methodResponse and no graph
            _idGenerator = new ObjectIDGenerator();
            _objectQueue = new Queue<object>();
            _formatterConverter = new FormatterConverter();
            _serObjectInfoInit = new SerObjectInfoInit();

            _topId = InternalGetId(graph, false, null, out isNew);
            headerId = -1;
            WriteSerializedStreamHeader(_topId, headerId);

            _objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId)) != null)
            {
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    objectInfo._assemId = GetAssemblyId(objectInfo);
                }

                objectInfo._objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            _objectManager.RaiseOnSerializedEvent();
        }
Esempio n. 18
0
        /* used by the runtime */
        private SerializationInfo(Type type)
        {
            assemblyName = type.GetTypeInfo().Assembly.FullName;
            fullTypeName = type.FullName;
            converter    = new FormatterConverter();
#if NET_4_0
            objectType = type;
#endif
        }
Esempio n. 19
0
        /// <summary>
        /// Extends Convert so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// iformatterconverter.Convert&lt;int&gt;(value);
        /// </example>
        /// </summary>
        public static T Convert <T>(this IFormatterConverter iformatterconverter, Object value)
        {
            if (iformatterconverter == null)
            {
                throw new ArgumentNullException("iformatterconverter");
            }

            return((T)iformatterconverter.Convert(value, typeof(T)));
        }
 public ObjectSerializer(
     SerializationConstructorFactory constructorFactory,
     SerializationCallbacksFactory serializationCallbacks,
     IFormatterConverter formatterConverter)
 {
     _constructorFactory     = constructorFactory;
     _serializationCallbacks = serializationCallbacks;
     _formatterConverter     = formatterConverter;
 }
Esempio n. 21
0
 internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, string assemblyName)
 {
     this.objectType         = objectType;
     this.objectManager      = objectManager;
     this.context            = context;
     this.serObjectInfoInit  = serObjectInfoInit;
     this.formatterConverter = converter;
     this.InitReadConstructor(objectType, surrogateSelector, context, assemblyName);
 }
Esempio n. 22
0
        public virtual void OnDeserialization(Object sender)
        {
            IFormatterConverter converter = null;
            SerializationInfo   siInfo    = new SerializationInfo(null, converter);

            //HashHelpers.SerializationInfoTable.TryGetValue(this, out siInfo);

            if (siInfo == null)
            {
                // It might be necessary to call OnDeserialization from a container if the container object also implements
                // OnDeserialization. However, remoting will call OnDeserialization again.
                // We can return immediately if this function is called twice.
                // Note we set remove the serialization info from the table at the end of this method.
                return;
            }

            int realVersion = siInfo.GetInt32(VersionName);
            int hashsize    = siInfo.GetInt32(HashSizeName);

            comparer = (IEqualityComparer <TKey>)siInfo.GetValue(ComparerName, typeof(IEqualityComparer <TKey>));

            if (hashsize != 0)
            {
                buckets = new int[hashsize];
                for (int i = 0; i < buckets.Length; i++)
                {
                    buckets[i] = -1;
                }
                entries  = new Entry[hashsize];
                freeList = -1;

                KeyValuePair <TKey, TValue>[] array = (KeyValuePair <TKey, TValue>[])
                                                      siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair <TKey, TValue>[]));

                if (array == null)
                {
                    //ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
                }

                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].Key == null)
                    {
                        //ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
                    }
                    Insert(array[i].Key, array[i].Value, true);
                }
            }
            else
            {
                buckets = null;
            }

            version = realVersion;
            //HashHelpers.SerializationInfoTable.Remove(this);
        }
 public void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerializationObjectInfo serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     this.ObjectType        = objectType;
     this.ObjectManager     = objectManager;
     this.context           = context;
     this.serObjectInfoInit = serObjectInfoInit;
     this.converter         = converter;
     this.isSimpleAssembly  = bSimpleAssembly;
     this.InitReadConstructor(objectType, surrogateSelector, context);
 }
 private void InitFullDeserialization()
 {
     this.fullDeserialization = true;
     this.stack         = new SerializationStack("ObjectReader Object Stack");
     this.objectManager = new ObjectManager(this.surrogates, this.context);
     if (this.converter == null)
     {
         this.converter = new FormatterConverter();
     }
 }
Esempio n. 25
0
 private void InitFullDeserialization()
 {
     _fullDeserialization = true;
     _stack         = new SerStack("ObjectReader Object Stack");
     _objectManager = new ObjectManager(_surrogates, _context, false, false);
     if (_formatterConverter == null)
     {
         _formatterConverter = new FormatterConverter();
     }
 }
        /// <summary>
        /// Create.
        /// </summary>
        public FastBinaryFormatter()
        {
            binder            = new DefaultSerializationBinder();
            context           = new StreamingContext();
            surrogateSelector = new SurrogateSelector();

            converter = new FormatterConverter();

            this.InternFieldNames = true;
        }
Esempio n. 27
0
 private void InitFullDeserialization()
 {
     this.bFullDeserialization = true;
     this.stack           = new SerStack("ObjectReader Object Stack");
     this.m_objectManager = new ObjectManager(this.m_surrogates, this.m_context, false, this.bIsCrossAppDomain);
     if (this.m_formatterConverter == null)
     {
         this.m_formatterConverter = new FormatterConverter();
     }
 }
Esempio n. 28
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);
        }
 public ValueTypeSerializerFactory(
     SerializationConstructorFactory constructorFactory,
     SerializationCallbacksFactory callbacksFactory,
     IFormatterConverter formatterConverter)
 {
     _constructorFactory       = constructorFactory;
     _callbacksFactory         = callbacksFactory;
     _formatterConverter       = formatterConverter;
     _createSerializerDelegate = type => (ValueTypeSerializer)
                                 _createTypedSerializerMethodInfo.MakeGenericMethod(type).Invoke(this, null);
 }
Esempio n. 30
0
        internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            _objectType         = objectType;
            _objectManager      = objectManager;
            _context            = context;
            _serObjectInfoInit  = serObjectInfoInit;
            _formatterConverter = converter;
            _isSimpleAssembly   = bSimpleAssembly;

            InitReadConstructor(objectType, surrogateSelector, context);
        }
 internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, FormatterHelper formatterEnums, SerializationBinder binder)
 {
     this._surrogates         = selector;
     this._context            = context;
     this._binder             = binder;
     this._formatterEnums     = formatterEnums;
     this.ObjectManager       = new SerializationObjectManager(context);
     this._idGenerator        = new ObjectIDGenerator();
     this._objectQueue        = new Queue <object>();
     this._formatterConverter = new FormatterConverter();
     this._serObjectInfoInit  = new SerializationObjectInfo();
 }
Esempio n. 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeserializationContext"/> class.
        /// </summary>
        /// <param name="context">The streaming context to use.</param>
        /// <param name="formatterConverter">The formatter converter to use.</param>
        /// <exception cref="System.ArgumentNullException">The formatterConverter parameter is null.</exception>
        public DeserializationContext(StreamingContext context, FormatterConverter formatterConverter)
        {
            if (formatterConverter == null)
            {
                throw new ArgumentNullException("formatterConverter");
            }

            this.streamingContext   = context;
            this.formatterConverter = formatterConverter;

            this.Reset();
        }
Esempio n. 33
0
 protected TypeCacheItem(Type outputType, IFormatterConverter conv)
 {
     Converter = conv;
     Type      = outputType;
     TypeName  = (string)Component.Convert(outputType, typeof(string), false);
     if (Type.IsValueType &&
         Type.IsGenericTypeDefinition == false &&
         Nullable.GetUnderlyingType(Type) == null)
     {
         DefaultValue = Activator.CreateInstance(Type);
     }
 }
 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();
         }
     }
 }
Esempio n. 35
0
		public SerializationInfo (Type type, IFormatterConverter converter)
		{
			if (type == null)
				throw new ArgumentNullException ("type", "Null argument");

			if (converter == null)
				throw new ArgumentNullException ("converter", "Null argument");
			
			this.converter = converter;
			assemblyName = type.Assembly.FullName;
			fullTypeName = type.FullName;
		}
Esempio n. 36
0
		/* used by the runtime */
		private SerializationInfo (Type type, SerializationEntry [] data)
		{
			int len = data.Length;

			assemblyName = type.Assembly.FullName;
			fullTypeName = type.FullName;
			converter = new FormatterConverter ();

			for (int i = 0; i < len; i++) {
				serialized.Add (data [i].Name, data [i]);
				values.Add (data [i]);
			}
		}
Esempio n. 37
0
 public ObjectSerializer(
     SerializationEntryCodec entrySerializer,
     SerializationConstructorFactory constructorFactory,
     SerializationCallbacksFactory serializationCallbacks,
     IFormatterConverter formatterConverter,
     StreamingContext streamingContext)
 {
     this.serializationCallbacks    = serializationCallbacks;
     this.formatterConverter        = formatterConverter;
     this.streamingContext          = streamingContext;
     this.entrySerializer           = entrySerializer;
     this.createConstructorDelegate = constructorFactory.GetSerializationConstructorDelegate;
 }
 internal ObjectWriter(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream", SoapUtil.GetResourceString("ArgumentNull_Stream"));
     }
     this.m_stream = stream;
     this.m_surrogates = selector;
     this.m_context = context;
     this.formatterEnums = formatterEnums;
     this.m_objectManager = new SerializationObjectManager(context);
     this.m_formatterConverter = new FormatterConverter();
 }
	public SerializationInfo(Type type, IFormatterConverter converter)
			{
				if(type == null)
				{
					throw new ArgumentNullException("type");
				}
				if(converter == null)
				{
					throw new ArgumentNullException("converter");
				}
				this.converter = converter;
				this.assemblyName = type.Assembly.FullName;
				this.fullTypeName = type.FullName;
				this.names = new ArrayList();
				this.values = new ArrayList();
				this.types = new ArrayList();
				this.generation = 0;
			}
Esempio n. 40
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);
            }
        }
Esempio n. 41
0
 public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (converter == null)
     {
         throw new ArgumentNullException("converter");
     }
     this.objectType = type;
     this.m_fullTypeName = type.FullName;
     this.m_assemName = type.Module.Assembly.FullName;
     this.m_members = new string[4];
     this.m_data = new object[4];
     this.m_types = new Type[4];
     this.m_converter = converter;
     this.m_currMember = 0;
     this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
 }
Esempio n. 42
0
        public SerializationInfo(Type type, IFormatterConverter converter)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (converter == null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            _rootType = type;
            _rootTypeName = type.FullName;
            _rootTypeAssemblyName = type.Module.Assembly.FullName;

            _names = new string[DefaultSize];
            _values = new object[DefaultSize];
            _types = new Type[DefaultSize];
            _nameToIndex = new LowLevelListDictionary();
            _converter = converter;
        }
 internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream", SoapUtil.GetResourceString("ArgumentNull_Stream"));
     }
     this.m_stream = stream;
     this.m_surrogates = selector;
     this.m_context = context;
     this.m_binder = binder;
     this.formatterEnums = formatterEnums;
     if (formatterEnums.FEtopObject != null)
     {
         this.IsFakeTopObject = true;
     }
     else
     {
         this.IsFakeTopObject = false;
     }
     this.m_formatterConverter = new FormatterConverter();
 }
        public SerializationInfo(Type type, IFormatterConverter converter) { 
            if ((object)type == null) { 
                throw new ArgumentNullException("type");
            } 

            if (converter==null) {
                throw new ArgumentNullException("converter");
            } 

            Contract.EndContractBlock(); 
 
            objectType = type;
            m_fullTypeName = type.FullName; 
            m_assemName = type.Module.Assembly.FullName;

            m_members = new String[defaultSize];
            m_data   = new Object[defaultSize]; 
            m_types  = new Type[defaultSize];
 
            m_converter = converter; 

            m_currMember = 0; 

        }
Esempio n. 45
0
        public SerializationInfo(Type type, IFormatterConverter converter)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (converter == null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            _rootType = type;
            _rootTypeName = type.FullName;
            _rootTypeAssemblyName = type.GetTypeInfo().Module.Assembly.FullName;

            _names = new String[defaultSize];
            _values = new object[defaultSize];
            _types = new Type[defaultSize];

            _nameToIndex = new Dictionary<string, int>();

            _converter = converter;
        }
 private void InitFullDeserialization()
 {
     this.bFullDeserialization = true;
     this.stack = new SerStack("ObjectReader Object Stack");
     this.m_objectManager = new ObjectManager(this.m_surrogates, this.m_context, false, this.bIsCrossAppDomain);
     if (this.m_formatterConverter == null)
     {
         this.m_formatterConverter = new FormatterConverter();
     }
 }
 public SerializationInfo(Type type, IFormatterConverter converter)
 {
   Contract.Requires(type.Module != null);
   Contract.Requires(type.Module.Assembly != null);
   Contract.Ensures(type.Module.Assembly != null);
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, bool fCheck)
        {
            if (graph == null)
                throw new ArgumentNullException("graph", Environment.GetResourceString("ArgumentNull_Graph"));

            if (serWriter == null)
                throw new ArgumentNullException("serWriter", Environment.GetResourceString("ArgumentNull_WithParamName", "serWriter"));
            Contract.EndContractBlock();

            SerTrace.Log(this, "Serialize Entry 2 ", graph, ((headers == null) ? " no headers " : "headers "));

            if (fCheck)
            {
                CodeAccessPermission.Demand(PermissionType.SecuritySerialization);          
            }

            this.serWriter = serWriter;
            this.headers = inHeaders;

            SerTrace.Log( this, "Serialize New SerializedTypeTable");
            serWriter.WriteBegin();
            long headerId = 0;
            Object obj;
            long objectId;
            bool isNew;
            bool bMethodCall = false;
            bool bMethodReturn = false;

#if FEATURE_REMOTING        
            // Special case IMethodCallMessage and IMethodReturnMessage for performance
            IMethodCallMessage mess = graph as IMethodCallMessage;
            if (mess != null)
            {
                bMethodCall = true;
                graph = WriteMethodCall(mess);
            }
            else
            {
                IMethodReturnMessage mr = graph as IMethodReturnMessage;
                if (mr != null)
                {
                    bMethodReturn = true;
                    graph = WriteMethodReturn(mr);
                }
            }
#endif // FEATURE_REMOTING        

            if (graph == null)
            {
                WriteSerializedStreamHeader(topId, headerId);

                if (bMethodCall)
                    serWriter.WriteMethodCall();
                else if (bMethodReturn)
                    serWriter.WriteMethodReturn();

                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
                return;
            }

            // allocations if methodCall or methodResponse and no graph
            m_idGenerator = new ObjectIDGenerator();
            m_objectQueue = new Queue();
            m_formatterConverter = new FormatterConverter();
            serObjectInfoInit = new SerObjectInfoInit();        

            topId = InternalGetId(graph, false, null, out isNew);


            if (headers != null)
                headerId = InternalGetId(headers, false, null, out isNew);
            else
                headerId = -1;

            WriteSerializedStreamHeader(topId, headerId);


            if (bMethodCall)
                serWriter.WriteMethodCall();
            else if (bMethodReturn)
                serWriter.WriteMethodReturn();


            SerTrace.Log( this, "Serialize Schedule 0");
            // Write out SerializedStream header
            if ((headers != null) && (headers.Length > 0))
                m_objectQueue.Enqueue(headers);                 

            if (graph != null)
                m_objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId))!=null)
            {
                SerTrace.Log( this, "Serialize GetNext ",obj);
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    SerTrace.Log( this, "Serialize GetNext recognizes WriteObjectInfo");
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, this, m_binder);
                    objectInfo.assemId = GetAssemblyId(objectInfo);
                }


                objectInfo.objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            m_objectManager.RaiseOnSerializedEvent();
            
            SerTrace.Log( this, "Serialize Exit ");
        }
Esempio n. 49
0
 public SerializationInfo(Type type, IFormatterConverter converter)
     : this(type, converter, false)
 {
 }
        [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);
        }
Esempio n. 51
0
        internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            _objectType = objectType;
            _objectManager = objectManager;
            _context = context;
            _serObjectInfoInit = serObjectInfoInit;
            _formatterConverter = converter;
            _isSimpleAssembly = bSimpleAssembly;

            InitReadConstructor(objectType, surrogateSelector, context);
        }
        [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);
            }
        }
        [System.Security.SecurityCritical]  // auto-generated 
        private void InitFullDeserialization()
        {
            bFullDeserialization = true;
            stack = new SerStack("ObjectReader Object Stack"); 
#if FEATURE_REMOTING
            m_objectManager = new ObjectManager(m_surrogates, m_context, false, bIsCrossAppDomain); 
#else 
            m_objectManager = new ObjectManager(m_surrogates, m_context, false, false);
#endif 
            if (m_formatterConverter == null)
                m_formatterConverter = new FormatterConverter();
        }
Esempio n. 54
0
        // XMLObjectWriter Constructor
        internal ObjectWriter(Stream stream, ISurrogateSelector selector, StreamingContext context,InternalFE formatterEnums)
        {
            if (stream==null)
            {
                throw new ArgumentNullException("stream", SoapUtil.GetResourceString("ArgumentNull_Stream"));               
            }

            m_stream=stream;
            m_surrogates = selector;
            m_context = context;
            this.formatterEnums = formatterEnums;
            InternalST.InfoSoap(
                               formatterEnums.FEtypeFormat +" "+
                               ((Enum)formatterEnums.FEserializerTypeEnum));

            m_formatterConverter = new FormatterConverter();

        }
        [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);
        }
 [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;
 }
Esempio n. 57
0
 internal void Init(Type objectType, string[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     _objectType = objectType;
     _objectManager = objectManager;
     _wireMemberNames = memberNames;
     _wireMemberTypes = memberTypes;
     _context = context;
     _serObjectInfoInit = serObjectInfoInit;
     _formatterConverter = converter;
     _isSimpleAssembly = bSimpleAssembly;
     if (memberTypes != null)
     {
         _isTyped = true;
     }
     if (objectType != null)
     {
         InitReadConstructor(objectType, surrogateSelector, context);
     }
 }
        [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);
        }
 [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;
 }
Esempio n. 60
0
        private void InitFullDeserialization()
        {
            bFullDeserialization = true;
            stack = new SerStack("ObjectReader Object Stack");

            m_objectManager = new ObjectManager(m_surrogates, m_context, false);
            if (m_formatterConverter == null)
                m_formatterConverter = new FormatterConverter();
        }