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


C# ImportDefinition.IsConstraintSatisfiedBy方法代碼示例

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


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

示例1: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(
            ImportDefinition definition,
            AtomicComposition atomicComposition
        ) {

            return from kv in _exports
                   where definition.IsConstraintSatisfiedBy(kv.Key)
                   select kv.Value;
        }
開發者ID:wenh123,項目名稱:PTVS,代碼行數:9,代碼來源:MockExportProvider.cs

示例2: IsAffectedImport

 private static bool IsAffectedImport(ImportDefinition import, IEnumerable<ExportDefinition> changedExports)
 {
     // This could be more efficient still if the export definitions were indexed by contract name,
     // only worth revisiting if we need to squeeze more performance out of recomposition
     foreach (var export in changedExports)
     {
         if (import.IsConstraintSatisfiedBy(export))
         {
             return true;
         }
     }
    
     return false;
 }
開發者ID:nlhepler,項目名稱:mono,代碼行數:14,代碼來源:ImportEngine.RecompositionManager.cs

示例3: IsProductConstraintSatisfiedBy

        internal static bool IsProductConstraintSatisfiedBy(ImportDefinition productImportDefinition, ExportDefinition exportDefinition)
        {
            object productValue = null;
            if (exportDefinition.Metadata.TryGetValue(CompositionConstants.ProductDefinitionMetadataName, out productValue))
            {
                ExportDefinition productDefinition = productValue as ExportDefinition;

                if (productDefinition != null)
                {
                    return productImportDefinition.IsConstraintSatisfiedBy(productDefinition);
                }
            }

            return false;
        }
開發者ID:RudoCris,項目名稱:Pinta,代碼行數:15,代碼來源:PartCreatorExportDefinition.cs

示例4: GetExports

            public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(
                ImportDefinition import)
            {
                var originalExports = this._originalCatalog.GetExports(import);
                var trimmedExports = originalExports.Where(partAndExport =>
                    !this._removedParts.ContainsKey(partAndExport.Item1));

                var addedExports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
                foreach (var part in this._addedParts)
                {
                    foreach (var export in part.ExportDefinitions)
                    {
                        if (import.IsConstraintSatisfiedBy(export))
                        {
                            addedExports.Add(new Tuple<ComposablePartDefinition, ExportDefinition>(part, export));
                        }
                    }
                }
                return trimmedExports.Concat(addedExports);
            }
開發者ID:grothag,項目名稱:pocketmef,代碼行數:20,代碼來源:CatalogExportProvider.CatalogChangeProxy.cs

示例5: GetExports

        /// <summary>
        ///     Returns the export definitions that match the constraint defined by the specified definition.
        /// </summary>
        /// <param name="definition">
        ///     The <see cref="ImportDefinition"/> that defines the conditions of the
        ///     <see cref="ExportDefinition"/> objects to return.
        /// </param>
        /// <returns>
        ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the
        ///     <see cref="ExportDefinition"/> objects and their associated
        ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined
        ///     by <paramref name="definition"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="definition"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ComposablePartCatalog"/> has been disposed of.
        /// </exception>
        /// <remarks>
        ///     <note type="inheritinfo">
        ///         Overriders of this property should never return <see langword="null"/>, if no
        ///         <see cref="ExportDefinition"/> match the conditions defined by
        ///         <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>.
        ///     </note>
        /// </remarks>
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            IEnumerable<ComposablePartDefinition> candidateParts = this.GetCandidateParts(definition);
            if (candidateParts == null)
            {
                return Enumerable.Empty<Tuple<ComposablePartDefinition, ExportDefinition>>();
            }

            var exports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
            foreach (var part in candidateParts)
            {
                foreach (var export in part.ExportDefinitions)
                {
                    if (definition.IsConstraintSatisfiedBy(export))
                    {
                        exports.Add(new Tuple<ComposablePartDefinition, ExportDefinition>(part, export));
                    }
                }
            }

            return exports;
        }
開發者ID:szKarlen,項目名稱:MEFMetadata,代碼行數:50,代碼來源:MetadataTypeCatalog.cs

示例6: GetExports

        public virtual IEnumerable<Tuple2<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(definition, "definition");

            var exports = new List<Tuple2<ComposablePartDefinition, ExportDefinition>>();
            foreach (var part in this.Parts)
            {
                foreach (var export in part.ExportDefinitions)
                {
                    if (definition.IsConstraintSatisfiedBy(export))
                    {
                        exports.Add(new Tuple2<ComposablePartDefinition, ExportDefinition>(part, export));
                    }
                }
            }
            return exports;

        }
開發者ID:ibratoev,項目名稱:MEF.NET35,代碼行數:20,代碼來源:ComposablePartCatalog.cs

示例7: GetExportsFromPublicSurface

        internal IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExportsFromPublicSurface(ImportDefinition definition)
        {
            Assumes.NotNull(definition, "definition");

            var exports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();

            foreach(var exportDefinition in this.PublicSurface)
            {
                if (definition.IsConstraintSatisfiedBy(exportDefinition))
                {
                    foreach (var export in this.GetExports(definition))
                    {
                        if(export.Item2 == exportDefinition)
                        {
                            exports.Add(export);
                            break;
                        }
                    }
                }
            }
            return exports;
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:22,代碼來源:CompositionScopeDefinition.cs

示例8: GetExports

        /// <summary>
        /// Returns the exports in the catalog that match a given definition of an import.
        /// This method is called every time MEF tries to satisfy an import.
        ///</summary>
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition importDef)
        {
            // If ImportMany is defined and we are at design-time the use the standard bahavior and return
            // all matching exports.
            if (importDef.Cardinality == ImportCardinality.ZeroOrMore && DesignTime)
            {
                return base.GetExports(importDef);
            }

            //otherwise we have to do our own logic
            IList<Tuple<ComposablePartDefinition, ExportDefinition>> result
                = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();

            // Walk through all parts in that catalog...
            foreach (ComposablePartDefinition partDef in Parts)
            {
                // ... and for each part, examine if any export definition matches the
                // requested import definition.
                foreach (ExportDefinition exportDef in partDef.ExportDefinitions)
                {
                    if (importDef.IsConstraintSatisfiedBy(exportDef))
                    {
                        //ok the import definition is satisfied
                        var matchingExport = new Tuple<ComposablePartDefinition, ExportDefinition>(partDef, exportDef);
                        object designTimeMetadata;
                        exportDef.Metadata.TryGetValue("DesignTime", out designTimeMetadata);
                        //if DesignTimeAttribute is set then ToBool returns the assigend value
                        //ohterwise it returns false 
                        bool hasDesignTimeAttribute = ToBool(designTimeMetadata);

                        //If ImportMany is defined and we are at run-time then filter out
                        //design-time exports
                        if (importDef.Cardinality == ImportCardinality.ZeroOrMore)
                        {
                            if (DesignTime || !hasDesignTimeAttribute)
                                result.Add(matchingExport);
                        }
                        //If Import or Import(AllowDefault=true) then prioritize design-time exports
                        //at design-time
                        else
                        {
                            if (DesignTime)
                            {
                                if (result.Count == 0) //also allow run-time exports at design-time
                                    result.Add(matchingExport);
                                else if (hasDesignTimeAttribute) //but prioritize design time data at design time
                                {
                                    result.Clear();
                                    result.Add(matchingExport);
                                }
                            }
                            else
                            {
                                if (!hasDesignTimeAttribute) //only allow run-time exports at run-time
                                    result.Add(matchingExport);
                            }
                        }
                    }
                }
            }
            return result;
        }
開發者ID:blackjacketproductions,項目名稱:Navigate,代碼行數:66,代碼來源:DrPartCatalog.cs

示例9: GetExportsCore

 protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
 {
     return Cache.Where(export => definition.IsConstraintSatisfiedBy(export.Definition));
 }
開發者ID:markrendle,項目名稱:MEFF,代碼行數:4,代碼來源:FunctionExportProvider.cs

示例10: GetExports

        internal virtual IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            List<Tuple<ComposablePartDefinition, ExportDefinition>> exports = null;
            foreach (var export in this.ExportDefinitions)
            {
                if (definition.IsConstraintSatisfiedBy(export))
                {
                    if (exports == null)
                    {
                        exports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
                    }
                    exports.Add(new Tuple<ComposablePartDefinition, ExportDefinition>(this, export));
                }
            }

            return exports ?? _EmptyExports;
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:17,代碼來源:ComposablePartDefinition.cs

示例11: EmptyContractName_ShouldMatchAllContractNames

        public void EmptyContractName_ShouldMatchAllContractNames()
        {
            var importDefinition = new ImportDefinition(ed => true, string.Empty, ImportCardinality.ZeroOrMore, false, false);

            var shouldMatch1 = new ExportDefinition("contract1", null);
            var shouldMatch2 = new ExportDefinition("contract2", null);

            Assert.IsTrue(importDefinition.IsConstraintSatisfiedBy(shouldMatch1));
            Assert.IsTrue(importDefinition.IsConstraintSatisfiedBy(shouldMatch2));
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:10,代碼來源:ImportDefinitionTests.cs

示例12: ContractName_ShouldBeIncludedInConstraintAutomatically

        public void ContractName_ShouldBeIncludedInConstraintAutomatically()
        {
            string testContractName = "TestContractName";
            var contractImportDefinition = new ImportDefinition(ed => true, testContractName, ImportCardinality.ZeroOrMore, false, false);

            var shouldMatch = new ExportDefinition(testContractName, null);
            var shouldNotMatch = new ExportDefinition(testContractName + testContractName, null);

            Assert.IsTrue(contractImportDefinition.IsConstraintSatisfiedBy(shouldMatch));
            Assert.IsFalse(contractImportDefinition.IsConstraintSatisfiedBy(shouldNotMatch));
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:11,代碼來源:ImportDefinitionTests.cs


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