Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Sep 23, 2020

Fixes: #461

Given this listener interface:

interface AnimatorListener {
    void onAnimationEnd (int param1);
    void onAnimationEnd (int param1, int param2);
}

Today we will generate 2 partial AnimationEndEventArgs classes:

// event args for java.code.AnimatorListener.onAnimationEnd
public partial class AnimationEndEventArgs : global::System.EventArgs {

	public AnimationEndEventArgs (int param1)
	{
		this.param1 = param1;
	}

	int param1;
	public int Param1 {
		get { return param1; }
	}
}

// event args for java.code.AnimatorListener.onAnimationEnd
public partial class AnimationEndEventArgs : global::System.EventArgs {

	public AnimationEndEventArgs (int param1, int param2)
	{
		this.param1 = param1;
		this.param2 = param2;
	}

	int param1;
	public int Param1 {
		get { return param1; }
	}

	int param2;
	public int Param2 {
		get { return param2; }
	}
}

This causes a compilation error:

The type 'AnimationEndEventArgs' already contains a definition for 'param1'

We need to detect these situations and instead combine multiple EventArgs classes into one, with a constructor for each method.

// event args for java.code.AnimatorListener.OnAnimationEnd
public partial class AnimationEndEventArgs : global::System.EventArgs {
    public AnimationEndEventArgs (int param1)
    {
        this.Param1 = param1;
    }

    public AnimationEndEventArgs (int param1, int param2)
    {
        this.Param1 = param1;
        this.Param2 = param2;
    }

    public int Param1 { get; private set; }
    public int Param2 { get; private set; }
}

Additionally, cleans up the generated code a little bit by using auto properties instead of fields.

@jpobst jpobst marked this pull request as ready for review September 23, 2020 15:14
@jonpryor jonpryor merged commit ee7afee into master Sep 25, 2020
@jonpryor jonpryor deleted the combine-eventargs branch September 25, 2020 00:26
@jpobst jpobst added this to the 11.1 (16.9 / 8.9) milestone Oct 13, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem binding EventArgs with different parameters

3 participants