Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fix bug in MS.CSharp handling non-generic classes nested in generic (#…
Browse files Browse the repository at this point in the history
…22117)

Such types are still generic but don't have a tick in their name, which
the name lookup expects all generic types' names to have.

Handle this case correctly.

Fixes #21689
  • Loading branch information
JonHanna authored and VSadov committed Jul 20, 2017
1 parent 4454822 commit a6dad05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,16 @@ private Name GetName(string p)
private Name GetName(Type type)
{
string name = type.Name;
return type.IsGenericType ? _nameManager.Add(name, name.IndexOf('`')) : _nameManager.Add(name);
if (type.IsGenericType)
{
int idx = name.IndexOf('`');
if (idx >= 0)
{
return _nameManager.Add(name, idx);
}
}

return _nameManager.Add(name);
}

#endregion
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.CSharp/tests/RuntimeBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,23 @@ public void InternalsVisibleToTest()
);
}

public class OuterType<T>
{
public class MyEntity
{
public int Id { get; set; }

public string Name { get; set; }
}
}

[Fact]
public void AccessMemberOfNonGenericNestedInGeneric()
{
Func<dynamic, int> dynamicDelegate = e => e.Id;
var dto = new OuterType<int>.MyEntity { Id = 1, Name = "Foo" };
Assert.Equal(1, dynamicDelegate(dto));
}

}
}

0 comments on commit a6dad05

Please sign in to comment.