本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例9: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
return Cache.Where(export => definition.IsConstraintSatisfiedBy(export.Definition));
}
示例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;
}
示例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));
}
示例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));
}