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


C# ConfigurationBuilder类代码示例

本文整理汇总了C#中ConfigurationBuilder的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder类的具体用法?C# ConfigurationBuilder怎么用?C# ConfigurationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConfigurationBuilder类属于命名空间,在下文中一共展示了ConfigurationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ArrayMerge

        public void ArrayMerge()
        {
            var json1 = @"{
                'ip': [
                    '1.2.3.4',
                    '7.8.9.10',
                    '11.12.13.14'
                ]
            }";

            var json2 = @"{
                'ip': {
                    '3': '15.16.17.18'
                }
            }";

            var jsonConfigSource1 = new JsonConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);
            jsonConfigSource1.Load(TestStreamHelpers.StringToStream(json1));

            var jsonConfigSource2 = new JsonConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);
            jsonConfigSource2.Load(TestStreamHelpers.StringToStream(json2));

            var builder = new ConfigurationBuilder();
            builder.Add(jsonConfigSource1, load: false);
            builder.Add(jsonConfigSource2, load: false);
            var config = builder.Build();

            Assert.Equal(4, config.GetSection("ip").GetChildren().Count());
            Assert.Equal("1.2.3.4", config["ip:0"]);
            Assert.Equal("7.8.9.10", config["ip:1"]);
            Assert.Equal("11.12.13.14", config["ip:2"]);
            Assert.Equal("15.16.17.18", config["ip:3"]);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:33,代码来源:ArrayTest.cs

示例2: Start

        /// <summary>
        /// Configure and run the KickStart extensions.
        /// </summary>
        /// <param name="configurator">The <see langword="delegate"/> to configure KickStart before execution of the extensions.</param>
        /// <example>Configure KickStart to use startup tasks using Autofac container to resolve <see cref="T:KickStart.StartupTask.IStartupTask" /> instances.
        /// <code><![CDATA[
        /// Kick.Start(config => config
        ///     .IncludeAssemblyFor<TestStartup>()
        ///     .UseAutofac()
        ///     .UseStartupTask(c => c.UseContainer())
        ///     .LogLevel(TraceLevel.Verbose)
        /// );]]></code>
        /// </example>
        public static void Start(Action<IConfigurationBuilder> configurator)
        {
            var config = new Configuration();
            var builder = new ConfigurationBuilder(config);

            configurator(builder);

            var assemblies = config.Assemblies.Resolve();
            var context = new Context(assemblies);

            foreach (var starter in config.Starters)
            {
                Logger.Trace()
                    .Logger(typeof(Kick).FullName)
                    .Message("Execute Starter: {0}", starter)
                    .Write();

                Stopwatch watch = Stopwatch.StartNew();

                starter.Run(context);

                watch.Stop();

                Logger.Trace()
                    .Logger(typeof(Kick).FullName)
                    .Message("Completed Starter: {0}, Time: {1} ms", starter, watch.ElapsedMilliseconds)
                    .Write();
            }
        }
开发者ID:modulexcite,项目名称:KickStart,代码行数:42,代码来源:Kick.cs

示例3: DifferentConfigSources_Merged_KeysAreSorted

        public void DifferentConfigSources_Merged_KeysAreSorted()
        {
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile(_json1ConfigFilePath);
            configurationBuilder.AddIniFile(_iniConfigFilePath);
            configurationBuilder.AddJsonFile(_json2ConfigFilePath);
            configurationBuilder.AddXmlFile(_xmlConfigFilePath);

            var config = configurationBuilder.Build();

            var configurationSection = config.GetSection("address");
            var indexConfigurationSections = configurationSection.GetChildren().ToArray();

            Assert.Equal(8, indexConfigurationSections.Length);
            Assert.Equal("0", indexConfigurationSections[0].Key);
            Assert.Equal("1", indexConfigurationSections[1].Key);
            Assert.Equal("2", indexConfigurationSections[2].Key);
            Assert.Equal("3", indexConfigurationSections[3].Key);
            Assert.Equal("4", indexConfigurationSections[4].Key);
            Assert.Equal("i", indexConfigurationSections[5].Key);
            Assert.Equal("j", indexConfigurationSections[6].Key);
            Assert.Equal("x", indexConfigurationSections[7].Key);

            Assert.Equal("address:0", indexConfigurationSections[0].Path);
            Assert.Equal("address:1", indexConfigurationSections[1].Path);
            Assert.Equal("address:2", indexConfigurationSections[2].Path);
            Assert.Equal("address:3", indexConfigurationSections[3].Path);
            Assert.Equal("address:4", indexConfigurationSections[4].Path);
            Assert.Equal("address:i", indexConfigurationSections[5].Path);
            Assert.Equal("address:j", indexConfigurationSections[6].Path);
            Assert.Equal("address:x", indexConfigurationSections[7].Path);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:32,代码来源:ArrayTests.cs

示例4: WithSimpleProperty_maps_properly

        public void WithSimpleProperty_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            var post = new Post() { Title = "test" };

            //Act
            builder
                .Resource<Post, PostsController>()
                .WithSimpleProperty(p => p.Title);

            var configuration = builder.Build();
            var mapping = configuration.GetMapping(typeof(Post));

            //Assert
            Assert.Equal(mapping.PropertyGetters.Count, 1);
            Assert.Equal(mapping.PropertySetters.Count, 1);

            var getter = mapping.PropertyGetters.Single().Value;
            var setter = mapping.PropertySetters.Single().Value;

            Assert.Equal(((string)getter(post)), "test");

            setter(post, "works");
            Assert.Equal(post.Title, "works");
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:26,代码来源:ConfigurationBuilderTest.cs

示例5: CanReAddMetaConfigurationSectionAfterChangeIsCanceled

        public void CanReAddMetaConfigurationSectionAfterChangeIsCanceled()
        {
            ConfigurationSettings existingSettings = null;
            using (ConfigurationBuilder originalConfigReader = new ConfigurationBuilder(configFile))
            {
                existingSettings = originalConfigReader.ReadMetaConfiguration();
            }

            try
            {
                builder.ConfigurationChanging += new ConfigurationChangingEventHandler(CancelingHandler);
                builder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnMetaDataConfigurationChanged);
                Thread.Sleep(100);
                builder.WriteMetaConfig(CreateNewConfigurationSection());
                Thread.Sleep(250);

                builder.ConfigurationChanging -= new ConfigurationChangingEventHandler(CancelingHandler);
                builder.ConfigurationChanging += new ConfigurationChangingEventHandler(AcceptingHandler);
                builder.WriteMetaConfig(CreateNewConfigurationSection());
                Thread.Sleep(250);

                Assert.AreEqual("ChangeCanceledChangeAcceptedMetaDataChanged", eventString);
            }
            finally
            {
                builder.WriteMetaConfiguration(existingSettings);
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:28,代码来源:ConfigurationBuilderFixture.cs

示例6: OnCreate

		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Autorize);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button>(Resource.Id.sumbit);

			button.Click += delegate {
				EditText textLogin = FindViewById<EditText> (Resource.Id.login);
				EditText textPass = FindViewById<EditText> (Resource.Id.password);
				string login = textLogin.Text.ToString ();
				string pass = textPass.Text.ToString ();
				// TODO change OAuth keys and tokens and username and password 

				config = new ConfigurationBuilder ();
				config.SetOAuthConsumerKey ("nz2FD8IELdrglLbNMJ1WeMsze");
				config.SetOAuthConsumerSecret ("Q5ZGt7Bc2McY3xdfjks3AU4yw5DKKSv0h3oXCTpjYhV25qwKL0");
				config.SetOAuthAccessToken ("4359603449-6z2CXsqmH4REQayCNgqwq71wM49PjbkSmNIUJil");
				config.SetOAuthAccessTokenSecret ("nAvebHjYLn1JXnO4PwqtmTBhPoet5rhIRUnlKghtmT8Ns");
				config.SetUser (login);
				config.SetPassword (pass);

				factory = new TwitterFactory (config.Build ());
				twitter = factory.Instance;

				GetInfo ();
			};
		}
开发者ID:okrotowa,项目名称:Mosigra.Yorsh,代码行数:32,代码来源:ShareToTwitterActivity.cs

示例7: WithAllProperties_maps_properly

        public void WithAllProperties_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new DefaultPropertyScanningConvention())
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());

            //Act
            builder
                .Resource<Post>()
                .WithAllProperties();

            builder.Resource<Author>();
            builder.Resource<Comment>();

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));

            //Assert
            postMapping.Relationships.Count.ShouldEqual(2);
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "authors").ShouldNotBeNull();
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "comments").ShouldNotBeNull();
            postMapping.PropertyGetters.Count.ShouldEqual(2);
            postMapping.PropertySetters.Count.ShouldEqual(2);
            postMapping.IdGetter.ShouldNotBeNull();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:29,代码来源:ConfigurationBuilderTest.cs

示例8: SetUp

 public void SetUp()
 {
     _contentRepository = new CmsContentRepositoryFake();
     _contentSourceRegistration = new ContentSourceRegistration(() => _contentRepository, null);
     _contentService = new ContentService(_contentSourceRegistration);
     _builder = new ConfigurationBuilder(_contentService);
 }
开发者ID:andrewmyhre,项目名称:ReallyTinyCms,代码行数:7,代码来源:ConfigurationBuilderTests.cs

示例9: NewConfigurationProviderOverridesOldOneWhenKeyIsDuplicated

        public void NewConfigurationProviderOverridesOldOneWhenKeyIsDuplicated()
        {
            // Arrange
            var dic1 = new Dictionary<string, string>()
                {
                    {"Key1:Key2", "ValueInMem1"}
                };
            var dic2 = new Dictionary<string, string>()
                {
                    {"Key1:Key2", "ValueInMem2"}
                };
            var memConfigSrc1 = new MemoryConfigurationProvider(dic1);
            var memConfigSrc2 = new MemoryConfigurationProvider(dic2);

            var configurationBuilder = new ConfigurationBuilder();

            // Act
            configurationBuilder.Add(memConfigSrc1, load: false);
            configurationBuilder.Add(memConfigSrc2, load: false);

            var config = configurationBuilder.Build();

            // Assert
            Assert.Equal("ValueInMem2", config["Key1:Key2"]);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:25,代码来源:ConfigurationTest.cs

示例10: ShouldBePreserved

        public void ShouldBePreserved()
        {
            var source = new TestSource
            {
                Foo = "Foobar",
                Bar = 32,
                Child = new TestEmbedded
                {
                    Blah = "o hai",
                    Qux = 64
                }
            };

            var compiled = new ConfigurationBuilder()
                .AddObject(source)
                .Build();

            var dest = new TestTarget();
            compiled.Bind(dest);

            dest.Foo.Should().Be("Foobar");
            dest.Bar.Should().Be(32);
            dest.Child.Blah.Should().Be("o hai");
            dest.Child.Qux.Should().Be(64);
        }
开发者ID:nbarbettini,项目名称:FlexibleConfiguration,代码行数:25,代码来源:ObjectGraph.cs

示例11: SerializeObject

        public object SerializeObject(ConfigurationBuilder serializerConfig, object obj)
        {
            var config = serializerConfig.Build();
            var sut = new JsonApiTransformer() { TransformationHelper = new TransformationHelper() };
            CompoundDocument result = sut.Transform(obj, new Context() { Configuration = config, RoutePrefix = _routePrefix });

            return result;
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:8,代码来源:JsonApiSerializer.cs

示例12: SetBasePath_CheckPropertiesValueOnBuilder

        public void SetBasePath_CheckPropertiesValueOnBuilder()
        {
            var expectedBasePath = @"C:\ExamplePath";
            var builder = new ConfigurationBuilder();

            builder.SetBasePath(expectedBasePath);
            Assert.Equal(expectedBasePath, builder.Properties["BasePath"]);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:8,代码来源:FileConfigurationBuilderExtensionsTest.cs

示例13: SetBasePath_ThrowsIfBasePathIsNull

        public void SetBasePath_ThrowsIfBasePathIsNull()
        {
            // Arrange
            var builder = new ConfigurationBuilder();

            // Act and Assert
            var ex = Assert.Throws<ArgumentNullException>(() => builder.SetBasePath(null));
            Assert.Equal("basePath", ex.ParamName);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:9,代码来源:FileConfigurationBuilderExtensionsTest.cs

示例14: WithLinkedResource_maps_properly

        public void WithLinkedResource_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());

            var post = new Post();
            var author = new Author
            {
                Posts = new List<Post> { post }
            };

            post.Author = author;
            post.AuthorId = 4;

            //Act
            builder
                .Resource<Post, PostsController>()
                .WithLinkedResource(p => p.Author);

            builder
                .Resource<Author, AuthorsController>()
                .WithLinkedResource(a => a.Posts);

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));
            var authorMapping = configuration.GetMapping(typeof(Author));

            //Assert
            Assert.Equal(postMapping.Relationships.Count, 1);

            var linkToAuthor = postMapping.Relationships.Single();

            Assert.False(linkToAuthor.IsCollection);
            Assert.Equal(linkToAuthor.RelationshipName, "author");
            Assert.Equal(linkToAuthor.ParentType, typeof(Post));
            Assert.Equal(linkToAuthor.RelatedBaseType, typeof(Author));
            Assert.Same(linkToAuthor.RelatedResource(post), author);
            Assert.Equal(linkToAuthor.RelatedResourceId(post), 4);
            Assert.Same(linkToAuthor.ResourceMapping, authorMapping);
            Assert.Equal(authorMapping.Relationships.Count, 1);
            
            var linkToPosts = authorMapping.Relationships.Single();

            Assert.True(linkToPosts.IsCollection);
            Assert.Equal(linkToPosts.RelationshipName, "posts");
            Assert.Equal(linkToPosts.ParentType, typeof(Author));
            Assert.Equal(linkToPosts.RelatedBaseType, typeof(Post));
            Assert.Same(linkToPosts.RelatedResource(author), author.Posts);
            Assert.Null(linkToPosts.RelatedResourceId);
            Assert.Same(linkToPosts.ResourceMapping, postMapping);
            
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:56,代码来源:ConfigurationBuilderTest.cs

示例15: AddJsonFile_ThrowsIfFilePathIsNullOrEmpty

        public void AddJsonFile_ThrowsIfFilePathIsNullOrEmpty(string path)
        {
            // Arrange
            var builder = new ConfigurationBuilder();

            // Act and Assert
            var ex = Assert.Throws<ArgumentException>(() => JsonConfigurationExtension.AddJsonFile(builder, path));
            Assert.Equal("path", ex.ParamName);
            Assert.StartsWith("File path must be a non-empty string.", ex.Message);
        }
开发者ID:rhwy,项目名称:Configuration,代码行数:10,代码来源:JsonConfigurationExtensionTest.cs


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