本文整理汇总了C#中ConventionBuilder.ForTypesMatching方法的典型用法代码示例。如果您正苦于以下问题:C# ConventionBuilder.ForTypesMatching方法的具体用法?C# ConventionBuilder.ForTypesMatching怎么用?C# ConventionBuilder.ForTypesMatching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConventionBuilder
的用法示例。
在下文中一共展示了ConventionBuilder.ForTypesMatching方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StandardExportInterfacesShouldWork
public void StandardExportInterfacesShouldWork()
{
// Export all interfaces except IDisposable, Export contracts on types without interfaces. except for disposable types
var builder = new ConventionBuilder();
builder.ForTypesMatching((t) => true).ExportInterfaces();
builder.ForTypesMatching((t) => t.GetTypeInfo().ImplementedInterfaces.Where((iface) => iface != typeof(System.IDisposable)).Count() == 0).Export();
var container = new ContainerConfiguration()
.WithPart<Standard>(builder)
.WithPart<Dippy>(builder)
.WithPart<Derived>(builder)
.WithPart<BareClass>(builder)
.CreateContainer();
var importer = new Importer();
container.SatisfyImports(importer);
Assert.NotNull(importer.First);
Assert.True(importer.First.Count() == 3);
Assert.NotNull(importer.Second);
Assert.True(importer.Second.Count() == 3);
Assert.NotNull(importer.Third);
Assert.True(importer.Third.Count() == 3);
Assert.NotNull(importer.Fourth);
Assert.True(importer.Fourth.Count() == 3);
Assert.NotNull(importer.Fifth);
Assert.True(importer.Fifth.Count() == 3);
Assert.Null(importer.Base);
Assert.Null(importer.Derived);
Assert.Null(importer.Dippy);
Assert.Null(importer.Standard);
Assert.Null(importer.Disposable);
Assert.NotNull(importer.BareClass);
}
示例2: AddPlatformSpecificConventions
static partial void AddPlatformSpecificConventions( ConventionBuilder builder )
{
var assembly = new PublicKeyTokenSpecification( typeof( Host ) );
var window = new AssignableSpecification<Window>().And( new AssignableSpecification<IShellView>().Not() );
var userControl = new AssignableSpecification<UserControl>().And( new AssignableSpecification<IShellView>().Not() );
builder.ForTypesMatching( window.IsSatisfiedBy ).Export().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
builder.ForTypesMatching( userControl.IsSatisfiedBy ).Export().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
}
示例3: AddPlatformSpecificConventions
static partial void AddPlatformSpecificConventions( ConventionBuilder builder )
{
var assembly = new PublicKeyTokenSpecification( typeof( Host ) );
var page = new PageSpecification();
var userControl = new UserControlSpecification();
builder.ForTypesMatching( page.IsSatisfiedBy ).Export().Export<Page>().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
builder.ForTypesMatching( userControl.IsSatisfiedBy ).Export().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
AddWinRTSpecificConventions( builder );
}
示例4: AddWinRTSpecificConventions
static partial void AddWinRTSpecificConventions( ConventionBuilder builder )
{
var assembly = new PublicKeyTokenSpecification( typeof( Host ) );
var settingsFlyout = new SettingsFlyoutSpecification();
builder.ForTypesMatching( settingsFlyout.IsSatisfiedBy ).Export().Export<SettingsFlyout>().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
}
示例5: AddUISpecificConventions
static partial void AddUISpecificConventions( ConventionBuilder builder )
{
var viewModel = new ViewModelSpecification();
builder.ForTypesDerivedFrom<IShellView>().Export().Export<IShellView>().Shared();
builder.ForTypesMatching( viewModel.IsSatisfiedBy ).Export();
builder.ForType<EventBroker>().Export<IEventBroker>().Shared();
}
示例6: GetContainerConfiguration
protected override ContainerConfiguration GetContainerConfiguration()
{
var conventionBuilder = new ConventionBuilder();
conventionBuilder.ForTypesMatching(type => type.FullName.EndsWith("View"))
.Export(builder => builder.AsContractType<object>()
.AsContractName("OkraPage")
.AddMetadata("PageName", type => type.Name.Substring(0, type.Name.Length - 4)));
conventionBuilder.ForTypesMatching(type => type.FullName.EndsWith("ViewModel"))
.Export(builder => builder.AsContractType<object>()
.AsContractName("OkraViewModel")
.AddMetadata("PageName", type => type.Name.Substring(0, type.Name.Length - 9)));
var ui = typeof(AppBootstrapper).GetTypeInfo().Assembly;
return GetOkraContainerConfiguration().WithAssemblies(new[] { ui }, conventionBuilder);
}
示例7: BuildMefConventions
public static void BuildMefConventions(ConventionBuilder conventionBuilder)
{
Contract.Requires(conventionBuilder != null);
// Export views as FrameworkElement with contract name as the type full name, so the ViewLocator can find it.
conventionBuilder.ForTypesMatching(t => t.Name.EndsWith("View"))
.Export<FrameworkElement>(
builder =>
builder.AsContractName(t => t.FullName));
}
示例8: ExportBuilderApiTestsNull_ShouldThrowArgumentNull
public void ExportBuilderApiTestsNull_ShouldThrowArgumentNull()
{
var builder = new ConventionBuilder();
ExceptionAssert.ThrowsArgumentNull("contractName", () => builder.ForTypesMatching((t) => true).Export(c => c.AsContractName(null as string)));
ExceptionAssert.ThrowsArgument("contractName", () => builder.ForTypesMatching((t) => true).Export(c => c.AsContractName("")));
ExceptionAssert.ThrowsArgumentNull("getContractNameFromPartType", () => builder.ForTypesMatching((t) => true).Export(c => c.AsContractName(null as Func<Type, string>)));
ExceptionAssert.ThrowsArgumentNull("type", () => builder.ForTypesMatching((t) => true).Export(c => c.AsContractType(null as Type)));
ExceptionAssert.ThrowsArgumentNull("name", () => builder.ForTypesMatching((t) => true).Export(c => c.AddMetadata(null as string, null as object)));
ExceptionAssert.ThrowsArgumentNull("name", () => builder.ForTypesMatching((t) => true).Export(c => c.AddMetadata(null as string, null as Func<Type, object>)));
ExceptionAssert.ThrowsArgumentNull("getValueFromPartType", () => builder.ForTypesMatching((t) => true).Export(c => c.AddMetadata("name", null as Func<Type, object>)));
}
示例9: DefineConventions
private static AttributedModelProvider DefineConventions()
{
var rb = new ConventionBuilder();
rb.ForTypesDerivedFrom<IController>().Export();
rb.ForTypesDerivedFrom<IHttpController>().Export();
rb.ForTypesMatching(IsAPart)
.Export()
.ExportInterfaces();
return rb;
}
示例10: BasicConvention
public void BasicConvention( ContainerConfiguration configuration, ConventionBuilder sut )
{
sut.ForTypesMatching( DragonSpark.Specifications.Common.Always.IsSatisfiedBy ).Export();
var types = this.Adapt().WithNested();
var container = configuration.WithParts( types, sut ).CreateContainer();
var export = container.GetExport<SomeExport>();
Assert.NotNull( export );
Assert.NotSame( export, container.GetExport<SomeExport>() );
var invalid = container.TryGet<Item>();
Assert.Null( invalid );
var shared = container.GetExport<SharedExport>();
Assert.NotNull( shared );
Assert.Same( shared, container.GetExport<SharedExport>() );
}
示例11: ConfigureMef
private static void ConfigureMef()
{
var conventions = new ConventionBuilder();
conventions.ForTypesDerivedFrom<ViewModelBase>()
.Export();
conventions.ForTypesMatching(x => x.Name.EndsWith("Service"))
.ExportInterfaces();
ViewLocator.BuildMefConventions(conventions);
var configuration = new ContainerConfiguration()
.WithAssembly(typeof(App).GetTypeInfo().Assembly, conventions)
.WithAssembly(typeof(LinquaLib).GetTypeInfo().Assembly, conventions)
.WithAssembly(typeof(FrameworkUwp).GetTypeInfo().Assembly)
.WithProvider(new DefaultExportDescriptorProvider());
var container = configuration.CreateContainer();
CompositionManager.Initialize(container);
App.CompositionManager = CompositionManager.Current;
}
示例12: TypesMarkedWithEagerlyConstructedAttributeAreConstructedEagerly
public void TypesMarkedWithEagerlyConstructedAttributeAreConstructedEagerly()
{
var conventions = new ConventionBuilder()
.WithEagerConstructionSupport();
conventions.ForTypesMatching(t => true).Export();
var configuration = new ContainerConfiguration()
.WithDefaultConventions(conventions)
.WithPart<ConstructionFlag>()
.WithPart<EagerPart>();
var container = configuration.CreateContainer();
var flag = container.GetExport<ConstructionFlag>();
Assert.IsFalse(flag.WasConstructed);
container.ConstructEagerParts();
Assert.IsTrue(flag.WasConstructed);
EagerPart stillExported;
Assert.IsTrue(container.TryGetExport(out stillExported));
}
示例13: CreateWithDefaultConventions
public static IDependencyResolver CreateWithDefaultConventions(Assembly[] appAssemblies)
{
var conventions = new ConventionBuilder();
conventions.ForTypesDerivedFrom<IHttpController>()
.Export();
conventions.ForTypesMatching(t => t.Namespace != null && t.Namespace.EndsWith(".Parts"))
.Export()
.ExportInterfaces();
var container = new ContainerConfiguration()
.WithAssemblies(appAssemblies, conventions)
.CreateContainer();
return new MefDependencyResolver(container);
}
示例14: ExportSelectorNull_ShouldThrowArgumentNull
public void ExportSelectorNull_ShouldThrowArgumentNull()
{
var builder = new ConventionBuilder();
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("propertySelector", () => builder.ForTypesMatching<IFoo>((t) => true).ExportProperty(null));
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("propertySelector", () => builder.ForTypesMatching<IFoo>((t) => true).ExportProperty(null, null));
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("propertySelector", () => builder.ForTypesMatching<IFoo>((t) => true).ExportProperty<IFirst>(null));
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("propertySelector", () => builder.ForTypesMatching<IFoo>((t) => true).ExportProperty<IFirst>(null, null));
}
示例15: ConstructorSelectorNull_ShouldThrowArgumentNull
public void ConstructorSelectorNull_ShouldThrowArgumentNull()
{
var builder = new ConventionBuilder();
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("constructorSelector", () => builder.ForTypesMatching<IFoo>((t) => true).SelectConstructor(null));
ExceptionAssert.ThrownMessageContains<ArgumentNullException>("importConfiguration", () => builder.ForTypesMatching<IFoo>((t) => true).SelectConstructor(null, null));
}