Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ private void EmitBindCoreImplForDictionary(DictionarySpec type)
Emit_Foreach_Section_In_ConfigChildren_StartBlock();

ParsableFromStringSpec keyType = (ParsableFromStringSpec)_typeIndex.GetEffectiveTypeSpec(type.KeyTypeRef);
TypeSpec elementType = _typeIndex.GetTypeSpec(type.ElementTypeRef);
TypeSpec elementType = _typeIndex.GetEffectiveTypeSpec(type.ElementTypeRef);

// Parse key
EmitBindingLogic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,5 +1131,21 @@ public class ParsableValuesClass
public Guid? GuidValue { get; set; }
public StringComparison? StringComparisonValue { get; set; }
}

public class OptionsWithCollectionsWithNullableEnum
{
// uses MyValue? dictionary values
public Dictionary<string, MyValue?> Dictionary { get; set; } = new();

// uses MyValue? List values
public List<MyValue?> List { get; set; } = new();
}

public enum MyValue
{
Value1,
Value2,
Value3
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,29 @@ public void CanGetEnumerableNotCollection()
Assert.Equal(new [] { "new", "class", "rosebud"}, result.Keywords);
}

[Fact]
public void TestDictionaryWithNullableEnumValueType()
{
var builder = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
{ "Settings:Dictionary:Key1", "Value2" },
{ "Settings:List:1", "Value3" },
});
var config = builder.Build();

var settingsSection = config.GetSection("Settings");
OptionsWithCollectionsWithNullableEnum settings = settingsSection.Get<OptionsWithCollectionsWithNullableEnum>()!;

Assert.NotNull(settings.Dictionary);
Assert.Equal(1, settings.Dictionary.Count);
Assert.Equal(MyValue.Value2, settings.Dictionary["Key1"]);

Assert.NotNull(settings.List);
Assert.Equal(1, settings.List.Count);
Assert.Equal(MyValue.Value3, settings.List[0]);
}

#if !BUILDING_SOURCE_GENERATOR_TESTS
[Fact]
public void EnsureThrowingWithCollectionAndErrorOnUnknownConfigurationOption()
Expand Down
Loading