当前位置: 首页>>代码示例>>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;未经允许,请勿转载。