You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jonathan Pobst edited this page Apr 6, 2021
·
3 revisions
When the bindings process sees something in the Java API that looks like an "event", it creates a C# event so that it feels more familiar for .NET users.
For example:
public class MyClass
{
public final void addOnPropertyChangeListener (OnPropertyChangeListener listener) { ... }
}
Generates:
public class MyClass
{
public unsafe void AddOnPropertyChangeListener (IOnPropertyChangeListener p0) { ... }
public event EventHandler<PropertyChangeEventArgs> PropertyChange;
}
The bindings process recognizes this pattern for:
addXXXListener
setXXXListener
Normally this is fine, however sometimes *both* of these methods exist in the same class for the same listener, which causes duplicate events to get generated:
public class MyClass
{
public unsafe void AddOnPropertyChangeListener (IOnPropertyChangeListener listener) { ... }
public unsafe void SetOnPropertyChangeListener (IOnPropertyChangeListener listener) { ... }
public event EventHandler<PropertyChangeEventArgs> PropertyChange;
public event EventHandler<PropertyChangeEventArgs> PropertyChange;
}
This results in compilation errors like:
Error CS0102: The type 'MyClass' already contains a definition for 'PropertyChange'
In order to fix this, we can use metadata on either method to specify that an event should not be generated for it, thus removing the duplicate. This is accomplished by specifying an empty value for the eventName attribute: