[ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. public void GetExports() { var catalog = new TypeCatalog(Assembly.GetExecutingAssembly().GetTypes()); Expression <Func <ExportDefinition, bool> > constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() >= 0); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > expectedMatchingExports = catalog.Parts .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple <ComposablePartDefinition, ExportDefinition>(part, export)) .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport))); Assert.True(matchingExports.SequenceEqual(expectedMatchingExports)); }
private static string NameForType <T>() { return(AttributedModelServices.GetContractName(typeof(T))); }
[ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. public void ICompositionElementDisplayName_ShouldIncludeDerivedCatalogTypeNameAndTypeFullNames() { var expectations = Expectations.GetAttributedTypes(); foreach (var e in expectations) { var catalog = (ICompositionElement) new DerivedTypeCatalog(e); string expected = string.Format(SR.TypeCatalog_DisplayNameFormat, typeof(DerivedTypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e)); Assert.Equal(expected, catalog.DisplayName); } }
private static ImportDefinition CreateImportDefinition(Type type, string metadataKey) { return(new ContractBasedImportDefinition(AttributedModelServices.GetContractName(typeof(IMyExporter)), null, new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>(metadataKey, typeof(object)) }, ImportCardinality.ZeroOrMore, true, true, CreationPolicy.Any)); }
private Export GetSingleLazy <T>(ComposablePart part) { return(this.GetSingleExport(part, AttributedModelServices.GetContractName(typeof(T)))); }
public MicroExport(Type contractType, IDictionary <string, object> metadata, params object[] exportedValues) : this(AttributedModelServices.GetContractName(contractType), exportedValues[0].GetType(), metadata, exportedValues) { }
public MicroExport(string contractName, Type contractType, IDictionary <string, object> metadata, params object[] exportedValues) { this.ContractName = contractName; this.ExportedValues = exportedValues; if (contractType != null) { string typeIdentity = AttributedModelServices.GetTypeIdentity(contractType); if (metadata == null) { metadata = new Dictionary <string, object>(); } object val; if (!metadata.TryGetValue(CompositionConstants.ExportTypeIdentityMetadataName, out val)) { metadata.Add(CompositionConstants.ExportTypeIdentityMetadataName, AttributedModelServices.GetTypeIdentity(contractType)); } } this.Metadata = metadata; }
public static string GetContractName(Type type) { Requires.NotNull(type, nameof(type)); return(AttributedModelServices.GetTypeIdentity(type)); }
public MicroExport(Type contractType, params object[] exportedValues) : this(AttributedModelServices.GetContractName(contractType), contractType, (IDictionary <string, object>)null, exportedValues) { }
public void GetExports() { var catalog = new AggregateCatalog(); Expression <Func <ExportDefinition, bool> > constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > matchingExports = null; matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() == 0); var testsDirectoryCatalog = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); catalog.Catalogs.Add(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() >= 0); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > expectedMatchingExports = catalog.Parts .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple <ComposablePartDefinition, ExportDefinition>(part, export)) .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport))); Assert.True(matchingExports.SequenceEqual(expectedMatchingExports)); catalog.Catalogs.Remove(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() == 0); }
public static ComposablePartDefinition CreatePartDefinition(Type type, ICompositionElement?origin) { Requires.NotNull(type, nameof(type)); return(AttributedModelServices.CreatePartDefinition(type, origin, false)); }
private static string[] GetContractNames(IEnumerable <Type> types) { return(GetContractNames(types.Select(t => AttributedModelServices.CreatePartDefinition(t, null)).SelectMany(p => p.ExportDefinitions))); }
private static object CreateStronglyTypedExportFactoryOfTM <T, M>(Export export, ConstructorInfo constructor) { Func <Tuple <T, Action> > exportLifetimeContextCreator = () => ExportServices.GetExportLifetimeContextFromExport <T>(export); return(constructor.Invoke(new object[] { exportLifetimeContextCreator, AttributedModelServices.GetMetadataView <M>(export.Metadata) })); }
public static CompositionScopeDefinition AsScopeWithPublicSurface <T>(this ComposablePartCatalog catalog, params CompositionScopeDefinition[] children) { IEnumerable <ExportDefinition> definitions = catalog.Parts.SelectMany((p) => p.ExportDefinitions.Where((e) => e.ContractName == AttributedModelServices.GetContractName(typeof(T)))); return(new CompositionScopeDefinition(catalog, children, definitions)); }
public static string GetContractName(Type type) { return(AttributedModelServices.GetTypeIdentity(type)); }
public void ICompositionElementDisplayName_SingleTypeAsTypesArgument_ShouldIncludeCatalogTypeNameAndTypeFullName() { var expectations = Expectations.GetAttributedTypes(); foreach (var e in expectations) { var catalog = (ICompositionElement)CreateTypeCatalog(e); string expected = string.Format(Strings.TypeCatalog_DisplayNameFormat, typeof(TypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e)); Assert.AreEqual(expected, catalog.DisplayName); } }