Exemplo n.º 1
0
 private void InitMemberInfo()
 {
     if (!_serObjectInfoInit.SeenBeforeTable.TryGetValue(_objectType, out _cache))
     {
         _cache = new SerializationObjectInfoCache(_objectType)
         {
             MemberInfos = FormatterServices.GetSerializableMembers(_objectType, _context)
         };
         int length = _cache.MemberInfos.Length;
         _cache.MemberNames = new string[length];
         _cache.MemberTypes = new Type[length];
         int index = 0;
         while (true)
         {
             if (index >= length)
             {
                 _serObjectInfoInit.SeenBeforeTable.Add(_objectType, _cache);
                 break;
             }
             _cache.MemberNames[index] = _cache.MemberInfos[index].Name;
             _cache.MemberTypes[index] = ((FieldInfo)_cache.MemberInfos[index]).FieldType;
             index++;
         }
     }
     if (_obj != null)
     {
         _memberData = FormatterServices.GetObjectData(_obj, _cache.MemberInfos);
     }
     _isNamed = true;
 }
Exemplo n.º 2
0
 private void InitNoMembers()
 {
     if (!_serObjectInfoInit.SeenBeforeTable.TryGetValue(_objectType, out _cache))
     {
         _cache = new SerializationObjectInfoCache(_objectType);
         _serObjectInfoInit.SeenBeforeTable.Add(_objectType, _cache);
     }
 }
Exemplo n.º 3
0
 private void InternalInit()
 {
     _obj                  = null;
     _objectType           = null;
     _isSi                 = false;
     _isNamed              = false;
     _isArray              = false;
     _si                   = null;
     _cache                = null;
     _memberData           = null;
     _objectId             = 0L;
     _assemId              = 0L;
     _binderTypeName       = null;
     _binderAssemblyString = null;
 }
 private void InitMemberInfo()
 {
     this.cache = new SerializationObjectInfoCache(this.ObjectType)
     {
         MemberInfos = FormatterServices.GetSerializableMembers(this.ObjectType, this.context)
     };
     this.count             = this.cache.MemberInfos.Length;
     this.cache.MemberNames = new string[this.count];
     this.cache.MemberTypes = new Type[this.count];
     for (int i = 0; i < this.count; i++)
     {
         this.cache.MemberNames[i] = this.cache.MemberInfos[i].Name;
         this.cache.MemberTypes[i] = this.GetMemberType(this.cache.MemberInfos[i]);
     }
     this.IsTyped = true;
 }
Exemplo n.º 5
0
        private void InitSiWrite()
        {
            _isSi = true;
            _     = _si.GetEnumerator();
            int             memberCount          = _si.MemberCount;
            TypeInformation typeInformation      = null;
            string          fullTypeName         = _si.FullTypeName;
            string          assemblyName         = _si.AssemblyName;
            bool            hasTypeForwardedFrom = false;

            if (!_si.IsFullTypeNameSetExplicit)
            {
                typeInformation      = BinaryFormatter.GetTypeInformation(_si.ObjectType);
                fullTypeName         = typeInformation.FullTypeName;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }
            if (!_si.IsAssemblyNameSetExplicit)
            {
                if (typeInformation == null)
                {
                    typeInformation = BinaryFormatter.GetTypeInformation(_si.ObjectType);
                }
                assemblyName         = typeInformation.AssemblyString;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }
            _cache = new SerializationObjectInfoCache(fullTypeName, assemblyName, hasTypeForwardedFrom)
            {
                MemberNames = new string[memberCount],
                MemberTypes = new Type[memberCount]
            };
            _memberData = new object[memberCount];
            SerializationInfoEnumerator enumerator = _si.GetEnumerator();

            for (int i = 0; enumerator.MoveNext(); i++)
            {
                _cache.MemberNames[i] = enumerator.Name;
                _cache.MemberTypes[i] = enumerator.ObjectType;
                _memberData[i]        = enumerator.Value;
            }
            _isNamed = true;
        }
Exemplo n.º 6
0
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationObjectInfo serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            _objectType        = objectType;
            _context           = context;
            _serObjectInfoInit = serObjectInfoInit;
            if (objectType.IsArray)
            {
                InitNoMembers();
            }
            else
            {
                InvokeSerializationBinder(binder);

                if (surrogateSelector != null)
                {
                    _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out _);
                }
                if (_serializationSurrogate != null)
                {
                    _si    = new SerializationInfo(objectType, converter);
                    _cache = new SerializationObjectInfoCache(objectType);
                    _isSi  = true;
                }
                else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
                {
                    _si    = new SerializationInfo(objectType, converter);
                    _cache = new SerializationObjectInfoCache(objectType);
                    //CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                    _isSi = true;
                }
                if (!_isSi)
                {
                    InitMemberInfo();
                    //CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                }
            }
        }
 private void InitNoMembers()
 {
     this.cache = new SerializationObjectInfoCache(this.ObjectType);
 }