GetTypeInformation() статический приватный Метод

static private GetTypeInformation ( Type type ) : TypeInformation
type System.Type
Результат TypeInformation
Пример #1
0
 private static void CheckTypeForwardedTo(Assembly sourceAssembly, Assembly destAssembly, Type resolvedType)
 {
     if ((!FormatterServices.UnsafeTypeForwardersIsEnabled() && (sourceAssembly != destAssembly)) && !destAssembly.PermissionSet.IsSubsetOf(sourceAssembly.PermissionSet))
     {
         TypeInformation typeInformation = BinaryFormatter.GetTypeInformation(resolvedType);
         if (!typeInformation.HasTypeForwardedFrom)
         {
             SecurityException exception2 = new SecurityException {
                 Demanded = sourceAssembly.PermissionSet
             };
             throw exception2;
         }
         Assembly assembly = null;
         try
         {
             assembly = Assembly.Load(typeInformation.AssemblyString);
         }
         catch
         {
         }
         if (assembly != sourceAssembly)
         {
             SecurityException exception = new SecurityException {
                 Demanded = sourceAssembly.PermissionSet
             };
             throw exception;
         }
     }
 }
Пример #2
0
        private static void CheckTypeForwardedTo(Assembly sourceAssembly, Assembly destAssembly, Type resolvedType)
        {
            if (FormatterServices.UnsafeTypeForwardersIsEnabled() || !(sourceAssembly != destAssembly) || destAssembly.PermissionSet.IsSubsetOf(sourceAssembly.PermissionSet))
            {
                return;
            }
            TypeInformation typeInformation = BinaryFormatter.GetTypeInformation(resolvedType);

            if (typeInformation.HasTypeForwardedFrom)
            {
                Assembly assembly = (Assembly)null;
                try
                {
                    assembly = Assembly.Load(typeInformation.AssemblyString);
                }
                catch
                {
                }
                if (assembly != sourceAssembly)
                {
                    throw new SecurityException()
                          {
                              Demanded = (object)sourceAssembly.PermissionSet
                          }
                }
                ;
            }
            else
            {
                throw new SecurityException()
                      {
                          Demanded = (object)sourceAssembly.PermissionSet
                      }
            };
        }
Пример #3
0
        internal SerObjectInfoCache(Type type)
        {
            TypeInformation typeInformation = BinaryFormatter.GetTypeInformation(type);

            _fullTypeName         = typeInformation.FullTypeName;
            _assemblyString       = typeInformation.AssemblyString;
            _hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
        }
Пример #4
0
        private void InitSiWrite()
        {
            SerTrace.Log(this, objectInfoId, " InitSiWrite Entry ");

            SerializationInfoEnumerator siEnum = null;

            isSi   = true;
            siEnum = si.GetEnumerator();
            int infoLength = 0;

            infoLength = si.MemberCount;

            int count = infoLength;

            // For ISerializable cache cannot be saved because each object instance can have different values
            // BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused.
            TypeInformation typeInformation      = null;
            string          fullTypeName         = si.FullTypeName;
            string          assemblyString       = 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);
                }
                assemblyString       = typeInformation.AssemblyString;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom);

            cache.memberNames = new String[count];
            cache.memberTypes = new Type[count];
            memberData        = new Object[count];

            siEnum = si.GetEnumerator();
            for (int i = 0; siEnum.MoveNext(); i++)
            {
                cache.memberNames[i] = siEnum.Name;
                cache.memberTypes[i] = siEnum.ObjectType;
                memberData[i]        = siEnum.Value;
                SerTrace.Log(this, objectInfoId + " ", objectType, " InitSiWrite ", cache.memberNames[i], " Type ", cache.memberTypes[i], " data ", memberData[i]);
            }

            isNamed = true;
            isTyped = false;

            SerTrace.Log(this, objectInfoId, " InitSiWrite Exit ");
        }
Пример #5
0
        private void InitSiWrite()
        {
            SerializationInfoEnumerator?siEnum = null;

            _isSi = true;
            Debug.Assert(_si != null);
            siEnum = _si.GetEnumerator();
            int infoLength = 0;

            infoLength = _si.MemberCount;

            int count = infoLength;

            // For ISerializable cache cannot be saved because each object instance can have different values
            // BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused.
            TypeInformation?typeInformation      = null;
            string          fullTypeName         = _si.FullTypeName;
            string          assemblyString       = _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);
                }
                assemblyString       = typeInformation.AssemblyString;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            _cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom);

            _cache._memberNames = new string[count];
            _cache._memberTypes = new Type[count];
            _memberData         = new object[count];

            siEnum = _si.GetEnumerator();
            for (int i = 0; siEnum.MoveNext(); i++)
            {
                _cache._memberNames[i] = siEnum.Name;
                _cache._memberTypes[i] = siEnum.ObjectType;
                _memberData[i]         = siEnum.Value;
            }

            _isNamed = true;
        }
Пример #6
0
        private void InitSiWrite()
        {
            SerializationInfoEnumerator serializationInfoEnumerator = (SerializationInfoEnumerator)null;

            this.isSi = true;
            serializationInfoEnumerator = this.si.GetEnumerator();
            int             memberCount          = this.si.MemberCount;
            TypeInformation typeInformation      = (TypeInformation)null;
            string          fullTypeName         = this.si.FullTypeName;
            string          assemblyName         = this.si.AssemblyName;
            bool            hasTypeForwardedFrom = false;

            if (!this.si.IsFullTypeNameSetExplicit)
            {
                typeInformation      = BinaryFormatter.GetTypeInformation(this.si.ObjectType);
                fullTypeName         = typeInformation.FullTypeName;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }
            if (!this.si.IsAssemblyNameSetExplicit)
            {
                if (typeInformation == null)
                {
                    typeInformation = BinaryFormatter.GetTypeInformation(this.si.ObjectType);
                }
                assemblyName         = typeInformation.AssemblyString;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }
            this.cache             = new SerObjectInfoCache(fullTypeName, assemblyName, hasTypeForwardedFrom);
            this.cache.memberNames = new string[memberCount];
            this.cache.memberTypes = new Type[memberCount];
            this.memberData        = new object[memberCount];
            SerializationInfoEnumerator enumerator = this.si.GetEnumerator();
            int index = 0;

            while (enumerator.MoveNext())
            {
                this.cache.memberNames[index] = enumerator.Name;
                this.cache.memberTypes[index] = enumerator.ObjectType;
                this.memberData[index]        = enumerator.Value;
                ++index;
            }
            this.isNamed = true;
            this.isTyped = false;
        }