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


C# ConventionBuilder.ForTypesMatching方法代码示例

本文整理汇总了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);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:35,代码来源:PartBuilderInterfaceTests.cs

示例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" );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:9,代码来源:Host.cs

示例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 );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:10,代码来源:Host.cs

示例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" );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:7,代码来源:Host.cs

示例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();
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:Host.cs

示例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);
        }
开发者ID:quandtm,项目名称:exXAMLate,代码行数:17,代码来源:AppBootstrapper.cs

示例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));
        }
开发者ID:pglazkov,项目名称:Linqua,代码行数:10,代码来源:ViewLocator.cs

示例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>)));
 }
开发者ID:nblumhardt,项目名称:corefx,代码行数:11,代码来源:ExportBuilderUnitTests.cs

示例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;
        }
开发者ID:SpectralAngel,项目名称:Antem,代码行数:14,代码来源:MvcContainerConfiguration.cs

示例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>() );
		}
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:16,代码来源:ConventionBuilderTests.cs

示例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;
        }
开发者ID:pglazkov,项目名称:Linqua,代码行数:24,代码来源:Bootstrapper.cs

示例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));
        }
开发者ID:blinds52,项目名称:alt-composition,代码行数:24,代码来源:EagerConstructionTests.cs

示例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);
        }
开发者ID:ChrisMissal,项目名称:WebApiContrib.IoC.Mef,代码行数:17,代码来源:MefDependencyResolver.cs

示例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));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:PartBuilderOfTTests.cs

示例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));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:PartBuilderOfTTests.cs


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