internal void AddValues(object values) { if (values == null) { return; } if (values is IEnumerable <KeyValuePair <string, object> > pairs) { // ASPNETCORE logger states and scopes are IReadOnlyList<KeyValuePair> foreach (var pair in pairs) { this[pair.Key] = pair.Value; } } else if (!typeof(IEnumerable).IsAssignableFrom(values.GetType())) { // Flat object was passed in var type = values.GetType(); var props = structurizer.CreateStructure(values); foreach (var index in props.Indexes) { this[index.Path] = index.Value; } } }
static void Main(string[] args) { //var typeConfigs = new StructureTypeConfigurations(); //typeConfigs.Register<Order>(cfg => cfg // .UsingIndexMode(IndexMode.Exclusive) // .Members(i => i.Lines[0].Props)); //inclusive:Lines.* //inclusive:Lines.ArticleNo //exclusive:Lines.* //exclusive.Lines.ArticleNo //var structureBuilder = StructureBuilder.Create(cfg => cfg.Register<Order>()); //var order = Order.CreateSample(); //var orderStructure = structureBuilder.CreateStructure(order); //DumpStructure(orderStructure); //var structureBuilder = StructureBuilder.Create(cfg => cfg.Register<Foo>()); //var foo = Foo.CreateSample(); //var fooStructure = structureBuilder.CreateStructure(foo); //DumpStructure(fooStructure); var flexibleStructureBuilder = new FlexibleStructureBuilder(); //Optionally configure //flexibleStructureBuilder.ConfigureUsingTemplate( // new { Age = default(int), Name = default(string) }, // c => c.Members(i => i.Age)); var structure1 = flexibleStructureBuilder.CreateStructure(new { Age = 37, Name = "Daniel" }); var structure2 = flexibleStructureBuilder.CreateStructure(new { Age = 36, Name = "John" }); DumpStructure(structure1); DumpStructure(structure2); Console.ReadLine(); }