當前位置: 首頁>>代碼示例>>C#>>正文


C# ExportProvider.GetExports方法代碼示例

本文整理匯總了C#中System.ComponentModel.Composition.Hosting.ExportProvider.GetExports方法的典型用法代碼示例。如果您正苦於以下問題:C# ExportProvider.GetExports方法的具體用法?C# ExportProvider.GetExports怎麽用?C# ExportProvider.GetExports使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.Composition.Hosting.ExportProvider的用法示例。


在下文中一共展示了ExportProvider.GetExports方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Configurate

        /// <summary>
        /// Configurates the specified export provider.
        /// </summary>
        /// <param name="exportProvider">The export provider.</param>
        /// <param name="loggerFactoryName">Name of the logger factory.</param>
        /// <exception cref="System.ArgumentNullException">exportProvider</exception>
        public static void Configurate(ExportProvider exportProvider, string loggerFactoryName = null)
        {
            if (exportProvider == null)
                throw new ArgumentNullException("exportProvider");

            var lazyLogFactory = exportProvider.GetExports<ILoggerFactory, ILoggerFactoryMetadata>()
                    .Where(f => string.IsNullOrEmpty(loggerFactoryName) || f.Metadata.Name.Equals(loggerFactoryName, StringComparison.OrdinalIgnoreCase))
                    .OrderBy(f => f.Metadata.Priority)
                    .FirstOrDefault();

            if (lazyLogFactory == null)
                return;

            var metadata = lazyLogFactory.Metadata;
            var configFiles = new List<string>();

            if (!string.IsNullOrEmpty(metadata.ConfigFileName))
            {
                configFiles.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, metadata.ConfigFileName));
                configFiles.Add(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"), metadata.ConfigFileName));
            }

            var facotry = lazyLogFactory.Value;

            if (!facotry.Initialize(configFiles.ToArray()))
                return;

            m_Current = facotry;
        }
開發者ID:kerryjiang,項目名稱:AnyLog,代碼行數:35,代碼來源:LoggerFactory.cs

示例2: ResolveAll

        /// <summary>
        /// Resolves an collection of objects wrapped inside <see cref="Lazy{T}"/>
        /// from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved collection of lazy instances or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="FactoryExportProvider"/>.
        /// </remarks>
        public static IEnumerable<Lazy<object>> ResolveAll(ExportProvider exportProvider, Type type, string name)
        {
            if (exportProvider == null)
            {
                throw new ArgumentNullException("exportProvider");
            }

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

            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return Enumerable.Empty<Lazy<object>>();
            
            var list = new List<Lazy<object>>();

            foreach (var export in exports)
            {
                var lazyExportMetadata = export.Metadata as IDictionary<string, object>;
                if (lazyExportMetadata != null &&
                    lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
                    true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
                {
                    continue;
                }

                list.Add(export);
            }

            return list;
        }
開發者ID:doublekill,項目名稱:MefContrib,代碼行數:46,代碼來源:ContainerServices.cs

示例3: Resolve

        /// <summary>
        /// Resolves an object wrapped inside <see cref="Lazy{T}"/> from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved instance or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="FactoryExportProvider"/>.
        /// </remarks>
        public static Lazy<object> Resolve(ExportProvider exportProvider, Type type, string name)
        {
            if (exportProvider == null)
            {
                throw new ArgumentNullException("exportProvider");
            }

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

            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return null;

            if (exports.Count() > 1)
                throw new ImportCardinalityMismatchException(Resources.TooManyInstances);

            var lazyExport = exports.First();
            var lazyExportMetadata = lazyExport.Metadata as IDictionary<string, object>;
            if (lazyExportMetadata != null &&
                lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
                true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
            {
                return null;
            }

            return lazyExport;
        }
開發者ID:doublekill,項目名稱:MefContrib,代碼行數:42,代碼來源:ContainerServices.cs

示例4: Resolve

        /// <summary>
        /// Resolves an object wrapped inside <see cref="Lazy{T}"/> from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved instance or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="RegistrationBasedFactoryExportProvider"/>.
        /// </remarks>
        public static Lazy<object> Resolve(ExportProvider exportProvider, Type type, string name)
        {
            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return null;

            if (exports.Count() > 1)
                throw new ImportCardinalityMismatchException(Resources.TooManyInstances);

            var lazyExport = exports.First();
            var lazyExportMetadata = lazyExport.Metadata as IDictionary<string, object>;
            if (lazyExportMetadata != null &&
                lazyExportMetadata.ContainsKey(ExporterConstants.IsContractBasedExportMetadataName) &&
                true.Equals(lazyExportMetadata[ExporterConstants.IsContractBasedExportMetadataName]))
            {
                return null;
            }

            return lazyExport;
        }
開發者ID:jbogard,項目名稱:MefContrib,代碼行數:32,代碼來源:ContainerServices.cs

示例5: ResolveAll

        /// <summary>
        /// Resolves an collection of objects wrapped inside <see cref="Lazy{T}"/>
        /// from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved collection of lazy instances or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="RegistrationBasedFactoryExportProvider"/>.
        /// </remarks>
        public static IEnumerable<Lazy<object>> ResolveAll(ExportProvider exportProvider, Type type, string name)
        {
            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return Enumerable.Empty<Lazy<object>>();

            var list = new List<Lazy<object>>();

            foreach (var export in exports)
            {
                var lazyExportMetadata = export.Metadata as IDictionary<string, object>;
                if (lazyExportMetadata != null &&
                    lazyExportMetadata.ContainsKey(ExporterConstants.IsContractBasedExportMetadataName) &&
                    true.Equals(lazyExportMetadata[ExporterConstants.IsContractBasedExportMetadataName]))
                {
                    continue;
                }

                list.Add(export);
            }

            return list;
        }
開發者ID:jbogard,項目名稱:MefContrib,代碼行數:36,代碼來源:ContainerServices.cs

示例6: AnalyzeImportDefinition

        static ImportDefinitionInfo AnalyzeImportDefinition(ExportProvider host, IEnumerable<PartDefinitionInfo> availableParts, ImportDefinition id)
        {
            IEnumerable<ExportDefinition> actuals = Enumerable.Empty<ExportDefinition>();
            Exception exception = null;
            IEnumerable<UnsuitableExportDefinitionInfo> unsuitableExportDefinitions =
                Enumerable.Empty<UnsuitableExportDefinitionInfo>();

            try
            {
                actuals = host.GetExports(id).Select(e => e.Definition).ToArray();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            var cbid = id as ContractBasedImportDefinition;
            if (cbid != null)
            {
                unsuitableExportDefinitions =
                    (from pd in availableParts
                    from ed in pd.PartDefinition.ExportDefinitions
                    where ed.ContractName == cbid.ContractName &&
                        !actuals.Contains(ed)
                    select new UnsuitableExportDefinitionInfo(cbid, ed, pd)).ToArray();
            }

            return new ImportDefinitionInfo(id, exception, actuals, unsuitableExportDefinitions);
        }
開發者ID:grothag,項目名稱:pocketmef,代碼行數:29,代碼來源:CompositionInfo.cs

示例7: TryGetExports

        private static CompositionResult<IEnumerable<Export>> TryGetExports(ExportProvider provider,
            ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition)
        {
            try
            {
                var exports = provider.GetExports(definition, atomicComposition).AsArray();
                return new CompositionResult<IEnumerable<Export>>(exports);
            }
            catch (ImportCardinalityMismatchException ex)
            {
                // Either not enough or too many exports that match the definition
                CompositionException exception = new CompositionException(ErrorBuilder.CreateImportCardinalityMismatch(ex, definition));

                return new CompositionResult<IEnumerable<Export>>(
                    ErrorBuilder.CreatePartCannotSetImport(part, definition, exception));
            }
        }
開發者ID:GuySrinivasan,項目名稱:mono,代碼行數:17,代碼來源:ImportEngine.cs


注:本文中的System.ComponentModel.Composition.Hosting.ExportProvider.GetExports方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。