cecilifier
cecilifier copied to clipboard
Accessing synthetic add_/remove_ methods of events declared in generic types throws a `NullReferenceException`
When processing events defined in generic types it seems we are ignoring the fact that the declaring type is generic when registering the add/remove_Event() methods and use the non generic version of the declaring type as the parent of the method.
Later we perform a lookup to figure out whether we have a forwarded access but this time using the generic name as the parent which fails so we try to forward declare the method and that fails with a NRE.
We need to:
- Ensure we use the correct (generic) name when registering
add/remove_{EventName}methods (potentially also with auto generated properties) - Try to come up with a scenario in which there is indeed a forward reference and fix the NRE in
MemberDeclarationSyntaxExtensions.Name()
Repro snippet:
using System;
class Bar<T>
{
public event Action Event;
}
class Foo
{
void M(Bar<int> b)
{
b.Event += () => {};
}
}