Exemple #1
0
        /// <summary>
        /// Adds all exported type in the <paramref name="assembly"/>
        /// of a specific <paramref name="contract"/> to the catalog.
        /// </summary>
        /// <param name="assembly">May be null. Assembly is then taken from the <paramref name="contract"/>.</param>
        /// <param name="contract">The export contract type. Must not be null.</param>
        public void AddMarkedTypesInAssembly(Assembly assembly, Type contract)
        {
            Contract.Requires(contract != null);
            Check.IfArgumentNull(contract, "contract");
            ThrowIfDisposed();

            if (assembly == null)
            {
                assembly = contract.Assembly;
            }

            var result = from type in assembly.GetTypes()
                         from attr in type.GetCustomAttributes(typeof(ExportAttribute), true)
                         where attr != null
                         where ((ExportAttribute)attr).ContractType != null
                         where ((ExportAttribute)attr).ContractType.FullName == contract.FullName
                         select type;

            var cat = new TypeCatalog(result);

            try
            {
                Contract.Assume(this.catalog.Catalogs != null);
                this.catalog.Catalogs.Add(cat);
            }
            catch
            {
                cat.Dispose();
                throw;
            }
        }
Exemple #2
0
        public void AddMarkedTypesInAssembly(Assembly assembly, string contract)
        {
            Contract.Requires(assembly != null);
            Contract.Requires(!String.IsNullOrEmpty(contract));
            Check.IfArgumentNull(assembly, "assembly");
            Check.IfArgumentNullOrEmpty(contract, "contract");
            ThrowIfDisposed();

            var result = from type in assembly.GetTypes()
                         from attr in type.GetCustomAttributes(typeof(ExportAttribute), true)
                         where ((ExportAttribute)attr).ContractName == contract
                         select type;

            var cat = new TypeCatalog(result);

            try
            {
                Contract.Assume(this.catalog.Catalogs != null);
                this.catalog.Catalogs.Add(cat);
            }
            catch
            {
                cat.Dispose();
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds these <paramref name="types"/> to the catalog.
        /// </summary>
        /// <param name="types">Must not be null.</param>
        public void AddTypes(params Type[] types)
        {
            Contract.Requires(types != null);
            Check.IfArgumentNull(types, "types");
            ThrowIfDisposed();

            var cat = new TypeCatalog(types);

            try
            {
                Contract.Assume(this.catalog.Catalogs != null);
                this.catalog.Catalogs.Add(cat);
            }
            catch
            {
                cat.Dispose();
                throw;
            }
        }