当前位置: 首页>>代码示例>>C#>>正文


C# Primitives.ImportDefinition类代码示例

本文整理汇总了C#中System.ComponentModel.Composition.Primitives.ImportDefinition的典型用法代码示例。如果您正苦于以下问题:C# ImportDefinition类的具体用法?C# ImportDefinition怎么用?C# ImportDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ImportDefinition类属于System.ComponentModel.Composition.Primitives命名空间,在下文中一共展示了ImportDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetImport

        public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
        {
            if (definition == null) throw new ArgumentNullException("definition");
            if (exports == null) throw new ArgumentNullException("exports");

            InterceptedPart.SetImport(definition, exports);
        }
开发者ID:damonrpayne,项目名称:MefContrib,代码行数:7,代码来源:InterceptingComposablePart.cs

示例2: GetExports

        public override System.Collections.Generic.IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var exports = base.GetExports(definition);
            if (GalaSoft.MvvmLight.ViewModelBase.IsInDesignModeStatic)
            {
                var designExports = exports.Where(export => (export.Item2.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName) &&
                    ((bool)export.Item2.Metadata[DesignTimeExportAttribute.DesignTimeMetadataName]) == true));

                if (designExports.Count() > 0)
                {
                    exports = designExports;
                }
                else
                {
                    exports = from export in exports
                              let ed = export.Item2
                              where !ed.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName)
                              select export;
                }
            }
            else
            {
                exports = from export in exports
                          let ed = export.Item2
                          where !ed.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName) || ((bool)ed.Metadata[DesignTimeExportAttribute.DesignTimeMetadataName]) == false
                          select export;
            }
            var a = exports.ToArray();
            return exports;
        }
开发者ID:kewkie,项目名称:WorkBalance,代码行数:30,代码来源:DesignTimeCatalog.cs

示例3: GetExports

        /// <summary>
        /// Method which can filter exports for given <see cref="ImportDefinition"/> or produce new exports.
        /// </summary>
        /// <param name="definition"><see cref="ImportDefinition"/> instance.</param>
        /// <param name="exports">A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</param>
        /// <returns>A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</returns>
        public IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition, IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> exports)
        {
            if (exports.Any())
            {
                return exports;
            }

            if (!CompositionServices.IsReflectionImportDefinition(definition))
            {
                return Enumerable.Empty<Tuple<ComposablePartDefinition, ExportDefinition>>();
            }

            var returnedExports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
            var importDefinitionType = CompositionServices.GetImportDefinitionType(definition);

            if (TypeHelper.IsGenericCollection(importDefinitionType))
            {
                importDefinitionType = TypeHelper.GetGenericCollectionParameter(importDefinitionType);
            }

            if (this.manufacturedParts.Contains(importDefinitionType))
            {
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }
            else if (TypeHelper.ShouldCreateClosedGenericPart(importDefinitionType))
            {
                CreateGenericParts(importDefinitionType);
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }

            return returnedExports;
        }
开发者ID:AndyWorral,项目名称:MefContrib,代码行数:40,代码来源:GenericExportHandler.cs

示例4: GetExportsCore

		protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
		{
			var serviceTypeName = definition.ContractName;
			if (serviceTypeName.IndexOf('.') == -1 ||
				serviceTypeName.StartsWith("System.") ||
				serviceTypeName.StartsWith("Clide."))
				return Enumerable.Empty<Export>();

			return serviceExports.GetOrAdd (serviceTypeName, contractName => {
				var serviceType = typeMap.GetOrAdd(contractName, typeName => MapType(typeName));
				if (serviceType == null)
					return Enumerable.Empty<Export>();

				// NOTE: if we can retrieve a valid instance of the service at least once, we 
				// assume we'll be able to retrieve it later on. Note also that we don't return 
				// the single retrieved instance from the export, but rather provide a function 
				// that does the GetService call every time, since we're caching the export but 
				// we don't know if the service can be safely cached.
				var service = services.GetService(serviceType);
				if (service == null)
					return Enumerable.Empty<Export>();

				return new Export[] { new Export(serviceTypeName, () => services.GetService(serviceType)) };
			});
		}
开发者ID:MobileEssentials,项目名称:clide,代码行数:25,代码来源:ServicesExportProvider.cs

示例5: GetExportsCore

        /// <summary>
        /// Gets the available set of exports for the given import definition.
        /// </summary>
        /// <param name="definition">The defintion of the import.</param>
        /// <param name="atomicComposition">The atomic composition of the import.</param>
        /// <returns>The available set of exports for the given import definition.</returns>
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Throw.IfArgumentNull(definition, "definition");
            if (SourceProvider == null)
                Throw.InvalidOperation(
                    string.Format(
                        CultureInfo.CurrentUICulture,
                        Resources.Exceptions.PropertyCannotBeNull,
                        "Sourceprovider"));

            var contractDefinition = definition as ContractBasedImportDefinition;
            if (contractDefinition == null
                || !contractDefinition.RequiredTypeIdentity.StartsWith(PartFactoryContractPrefix))
                return EmptyExports;

            var info = _definitionCache.Fetch(contractDefinition, () => new PartFactoryImport(contractDefinition));

            var exports = SourceProvider.GetExports(info.ImportDefinition, atomicComposition);
            var result = exports
                .Select(e => info.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var export in exports.OfType<IDisposable>())
                export.Dispose();

            return result;
        }
开发者ID:jd-pantheon,项目名称:Titan-Framework-v2,代码行数:33,代码来源:DynamicInstantiationExportProvider.cs

示例6: GetExports

        public IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition, IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> exports)
        {
            var contractDef = (ContractBasedImportDefinition)definition;
            var returnedExports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
            var importDefinitionType = TypeHelper.GetImportDefinitionType(definition);

            if (exports.Any())
            {
                return exports;
            }

            returnedExports.Concat(exports);

            if (this.manufacturedParts.Contains(importDefinitionType))
            {
                returnedExports.AddRange(this.catalog.GetExports(definition));
            }
            else if (TypeHelper.ShouldCreateClosedGenericPart(contractDef, importDefinitionType))
            {
                CreateGenericPart(importDefinitionType);
                returnedExports.AddRange(this.catalog.GetExports(definition));
            }

            return returnedExports;
        }
开发者ID:damonrpayne,项目名称:MefContrib,代码行数:25,代码来源:GenericExportHandler.cs

示例7: GetExports

 public override IEnumerable<TempTuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
 {
     LambdaExpression lambda = definition.Constraint;
     if (lambda.Body is BinaryExpression)
     {
         BinaryExpression binaryExpression = (BinaryExpression)lambda.Body;
         if (binaryExpression.Left is MemberExpression && ((MemberExpression)binaryExpression.Left).Member.Name == "ContractName")
         {
             IList<IService> services = resolver.Resolve((string)((ConstantExpression)binaryExpression.Right).Value, TimeOut, definition.Cardinality == ImportCardinality.ZeroOrOne ? 0 : 1, definition.Cardinality == ImportCardinality.ZeroOrMore ? int.MaxValue : 1);
             foreach (IService service in services)
                 resolver_ServiceFound(service);
         }
     }
     var exports = new List<TempTuple<ComposablePartDefinition, ExportDefinition>>();
     foreach (var part in this.Parts.ToArray())
     {
         foreach (var export in part.ExportDefinitions)
         {
             if (definition.Constraint.Compile().Invoke(export))
             {
                 exports.Add(new TempTuple<ComposablePartDefinition, ExportDefinition>(part, export));
             }
         }
     }
     return exports;
 }
开发者ID:RoyDoron,项目名称:bonjour.net,代码行数:26,代码来源:Catalog.cs

示例8: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            if (definition == null) throw new ArgumentNullException("definition");
            if (SourceProvider == null) throw new InvalidOperationException("SourceProvider must be set.");

            var cbid = definition as ContractBasedImportDefinition;

            if (cbid == null || !cbid.RequiredTypeIdentity.StartsWith(PartCreatorContractPrefix))
                return EmptyExports;

            var importInfo = _importDefinitionCache.GetOrCreate(
                cbid,
                () => new ExportFactoryImport(cbid));

            var sourceExports = SourceProvider
                .GetExports(importInfo.ProductImport, atomicComposition);

            var result = sourceExports
                .Select(e => importInfo.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var e in sourceExports.OfType<IDisposable>())
                e.Dispose();

            return result;
        }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:26,代码来源:ExportFactoryInstantiationProvider.cs

示例9: SetImport

        public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
        {
            Contract.Requires(definition != null);
            Contract.Requires(exports != null);

            throw new NotImplementedException();
        }
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:ContractAdditions.cs

示例10: SetImport

            public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
            {
                Requires.NotNull(definition, "definition");
                Requires.NotNullOrNullElements(exports, "exports");

                throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
            }
开发者ID:RudoCris,项目名称:Pinta,代码行数:7,代码来源:CompositionBatch.SingleExportComposablePart.cs

示例11: GetExportsCore

            protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
            {
                List<Export> exports = new List<Export>();

                ImportDefinition queryImport = TranslateImport(definition);
                if (queryImport == null)
                {
                    return exports;
                }

                // go through the catalogs and see if there's anything there of interest
                foreach (CompositionScopeDefinition childCatalog in this._scopeDefinition.Children)
                {
                    foreach (var partDefinitionAndExportDefinition in childCatalog.GetExportsFromPublicSurface(queryImport))
                    {
                        using (var container = this.CreateChildContainer(childCatalog))
                        {
                            // We create a nested AtomicComposition() because the container will be Disposed and 
                            // the RevertActions need to operate before we Dispose the child container
                            using (var ac = new AtomicComposition(atomicComposition))
                            {
                                var childCatalogExportProvider = container.CatalogExportProvider;
                                if (!childCatalogExportProvider.DetermineRejection(partDefinitionAndExportDefinition.Item1, ac))
                                {
                                    exports.Add(this.CreateScopeExport(childCatalog, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2));
                                }
                            }
                        }
                    }
                }

                return exports;
            }
开发者ID:nlhepler,项目名称:mono,代码行数:33,代码来源:CatalogExportProvider.ScopeManager.cs

示例12: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var contractName = definition.ContractName;

            if (contractName != SettingsConstants.SettingsContract)
                yield break;

            if (definition.Cardinality == ImportCardinality.ZeroOrMore)
                yield break;

            // TODO can't figure out how to get data injected into the Metadata collection
            //string settingsKey = definition.Metadata[SettingsConstants.SettingsMetadataKey] as string;

            LazyMemberInfo lazyMember = ReflectionModelServices.GetImportingMember(definition);
            MemberInfo member = lazyMember.GetAccessors().First();

            MethodInfo getterOrSetter = (MethodInfo)member;
            
            // HACK this is pretty evil
            PropertyInfo propInfo = getterOrSetter.DeclaringType.GetProperty(getterOrSetter.Name.Substring(4));

            ImportSettingAttribute settingsAttr = propInfo.GetCustomAttribute<ImportSettingAttribute>();

            if (settingsAttr == null)
                yield break;

            object value;
            if (!this._settingsProvider.TryGetValue(settingsAttr.SettingsKey, out value))
                yield break;

            yield return new Export(SettingsConstants.SettingsContract, () => value);
        }
开发者ID:LBiNetherlands,项目名称:LBi.LostDoc,代码行数:32,代码来源:SettingsExportProvider.cs

示例13: TranslateImport

        private static ImportDefinition TranslateImport(ImportDefinition import, ComposablePartDefinition part)
        {
            ContractBasedImportDefinition contractBasedImport = import as ContractBasedImportDefinition;
            if (contractBasedImport == null)
            {
                return import;
            }

            int[] importParametersOrder = contractBasedImport.Metadata.GetValue<int[]>(CompositionConstants.GenericImportParametersOrderMetadataName);
            if (importParametersOrder == null)
            {
                return import;
            }

            int partArity = part.Metadata.GetValue<int>(CompositionConstants.GenericPartArityMetadataName);
            if (partArity == 0)
            {
                return import;
            }

            string contractName = GenericServices.GetGenericName(contractBasedImport.ContractName, importParametersOrder, partArity);
            string requiredTypeIdentity = GenericServices.GetGenericName(contractBasedImport.RequiredTypeIdentity, importParametersOrder, partArity);
            return new ContractBasedImportDefinition(
                         contractName,
                         requiredTypeIdentity,
                         contractBasedImport.RequiredMetadata,
                         contractBasedImport.Cardinality,
                         contractBasedImport.IsRecomposable,
                         false,
                         contractBasedImport.RequiredCreationPolicy,
                         contractBasedImport.Metadata);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:PrimitivesServices.cs

示例14: GetExports

        /// <summary>
        /// Returns the available exports for the specified import definition.
        /// </summary>
        /// <param name="definition">The import definition.</param>
        /// <returns>The set of matching exports.</returns>
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var definitions = _catalog.GetExports(definition);

            var list = HttpContext.Current.ModelList<ImportDescriptor>("MEF-Imports");

            var model = new ImportDescriptor
                            {
                                Cardinality = definition.Cardinality.ToString(),
                                ContractName = definition.ContractName,
                                Prerequisite = definition.IsPrerequisite,
                                Recomposable = definition.IsRecomposable
                            };

            foreach (var def in definitions)
            {
                var meta = def.Item2.Metadata.Keys
                    .Where(k => k != CreationPolicyTypeName)
                    .ToDictionary(key => key, key => def.Item2.Metadata[key].ToString());

                string policy = null;
                if (def.Item2.Metadata.ContainsKey(CreationPolicyTypeName))
                    policy = def.Item2.Metadata[CreationPolicyTypeName].ToString();

                var export = new ExportDescriptor { CreationPolicy = policy, DisplayName = def.Item1.ToString(), Metadata = meta };

                model.Exports.Add(export);
            }

            list.Add(model);

            return definitions;
        }
开发者ID:Antaris,项目名称:Glimpse.MEF,代码行数:38,代码来源:GlimpseCatalog.cs

示例15: CacheImportDefinition

        public IDictionary<string, object> CacheImportDefinition(ComposablePartDefinition owner, ImportDefinition importDefinition)
        {
            ContractBasedImportDefinition contractBasedImport = importDefinition as ContractBasedImportDefinition;
            Assumes.NotNull(contractBasedImport);

            return CompositionCacheServices.WriteImportDefinition(owner, contractBasedImport);
        }
开发者ID:ibratoev,项目名称:MEF.NET35,代码行数:7,代码来源:AttributedComposablePartCatalogSite.cs


注:本文中的System.ComponentModel.Composition.Primitives.ImportDefinition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。