Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dotnet): Fix property set for nested Dictionaries #736

Merged
merged 2 commits into from
Aug 26, 2019
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 @@ -91,6 +91,19 @@ public void CollectionTypes()
types.MapProperty = map;
Assert.Equal((double) 123, types.MapProperty["Foo"].Value);
}

[Fact(DisplayName = Prefix + nameof(ComplexCollectionTypes))]
public void ComplexCollectionTypes()
{
// See https://github.com/aws/aws-cdk/issues/2496
AllTypes types = new AllTypes();
// complex map
IDictionary<string, object> map = new Dictionary<string, object>();
map.Add("Foo", new Dictionary<string, object>() { {"Key", 123d}});
types.AnyMapProperty = map;
var dict = (Dictionary<string, object>)types.AnyMapProperty["Foo"];
Assert.Equal(123d, dict["Key"]);
}

[Fact(DisplayName = Prefix + nameof(DynamicTypes))]
public void DynamicTypes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,16 @@ protected override bool TryConvertMap(IReferenceMap referenceMap, TypeReference
foreach (string key in keys)
{
object element = indexer.GetValue(value, new object[] {key});
if (!TryConvert(elementType, referenceMap, element, out object convertedElement))

TypeReference childElementType = InferType(referenceMap, element);

// We should not pass the parent element type as we are in a map
// A map<string, object> could be a map<string, map<string, object> etc
// If we pass the parent referenceMap then it will try to convert it as Any
// So by inferring the child element type we are always converting the correct type.
// See https://github.com/aws/aws-cdk/issues/2496

if (!TryConvert(childElementType, referenceMap, element, out object convertedElement))
{
result = null;
return false;
Expand Down