public void IgnoresReadOnlyNestedStructProperties() { ConfigurationBuilder configurationBuilder = new(); configurationBuilder.AddInMemoryCollection(new Dictionary <string, string> { { "ReadOnlyNestedStruct:String", "s" }, { "ReadOnlyNestedStruct:DeeplyNested:Int32", "100" }, { "ReadOnlyNestedStruct:DeeplyNested:Boolean", "true" }, }); IConfiguration config = configurationBuilder.Build(); StructWithNestedStructs bound = config.Get <StructWithNestedStructs>(); Assert.Null(bound.ReadOnlyNestedStruct.String); Assert.Equal(0, bound.ReadWriteNestedStruct.DeeplyNested.Int32); Assert.False(bound.ReadWriteNestedStruct.DeeplyNested.Boolean); }
public void CanBindNullableNestedStructProperties() { ConfigurationBuilder configurationBuilder = new(); configurationBuilder.AddInMemoryCollection(new Dictionary <string, string> { { "NullableNestedStruct:String", "s" }, { "NullableNestedStruct:DeeplyNested:Int32", "100" }, { "NullableNestedStruct:DeeplyNested:Boolean", "true" }, }); IConfiguration config = configurationBuilder.Build(); StructWithNestedStructs bound = config.Get <StructWithNestedStructs>(); Assert.NotNull(bound.NullableNestedStruct); Assert.Equal("s", bound.NullableNestedStruct.Value.String); Assert.Equal(100, bound.NullableNestedStruct.Value.DeeplyNested.Int32); Assert.True(bound.NullableNestedStruct.Value.DeeplyNested.Boolean); }