Exemple #1
0
        public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (assembly.ReflectionOnly)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly"));
            }
            RuntimeAssembly runtimeAssembly = assembly as RuntimeAssembly;

            if (runtimeAssembly == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));
            }
            string fullName = assembly.FullName;

            if (fullName == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmName"));
            }
            string text = null;

            if ((flags & AssemblyRegistrationFlags.SetCodeBase) != AssemblyRegistrationFlags.None)
            {
                text = runtimeAssembly.GetCodeBase(false);
                if (text == null)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmCodeBase"));
                }
            }
            Type[] registrableTypesInAssembly = this.GetRegistrableTypesInAssembly(assembly);
            int    num                 = registrableTypesInAssembly.Length;
            string strAsmVersion       = runtimeAssembly.GetVersion().ToString();
            string imageRuntimeVersion = assembly.ImageRuntimeVersion;

            for (int i = 0; i < num; i++)
            {
                if (this.IsRegisteredAsValueType(registrableTypesInAssembly[i]))
                {
                    this.RegisterValueType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                else if (this.TypeRepresentsComType(registrableTypesInAssembly[i]))
                {
                    this.RegisterComImportedType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                else
                {
                    this.RegisterManagedType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                this.CallUserDefinedRegistrationMethod(registrableTypesInAssembly[i], true);
            }
            object[] customAttributes = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false);
            int      num2             = customAttributes.Length;

            for (int j = 0; j < num2; j++)
            {
                this.RegisterPrimaryInteropAssembly(runtimeAssembly, text, (PrimaryInteropAssemblyAttribute)customAttributes[j]);
            }
            return(registrableTypesInAssembly.Length != 0 || num2 > 0);
        }