How to rename the Event Name in xamarin.android binding?

mc 5,426 Reputation points
2021-04-05T14:24:24.84+00:00

I am binding an .aar to android and there is one Event I have to change its name.
public event EventHandler<global::Com.xxx.xxx.A.BEventArgs> B{}

I want to change the name of B

but I can not . how to change it?

the interfaces of java is:

public static interface OnBListener{ void OnB(); }

there is a region #region "Event implementation for IOnBListener" in the cs code.

Developer technologies .NET Xamarin
{count} votes

3 answers

Sort by: Most helpful
  1. Zola 1 Reputation point
    2021-08-30T22:39:52.347+00:00

    Did you finally get the correct answer? the proposed solution isn't working for me also

    0 comments No comments

  2. NullObjectReference 1 Reputation point
    2022-06-14T22:25:58.507+00:00

    @mc , @Zola
    The only way to change event name that works for me is changing of managed name of corresponding setEventListener mathod.
    So if you have java sources

    /// Listener interface  
    public interface OnBListener  
    {  
        void onB();   
    }  
    

    And

    // Listener consumer class  
    public class ListenerConsumer  
    {  
        public void setOnBListener(OnBListener listener) { }  
    }  
    

    You can change managed name of ListenerConsumer.setOnBListener:

    <attr    
        path="/api/package[@name='com.xxx.xxx']/class[@name='ListenerConsumer']/method[@name='setOnBListener']"   
        name="managedName">SetOnDListener</attr>  
    

    In this case name of generated event in C# code will be D instead of B.

    0 comments No comments

  3. NullObjectReference 1 Reputation point
    2022-06-18T14:17:41.7+00:00

    Finally I found correct way to control generated event names. name="eventName" attribute can be applied to corresponding setOnListener method. For example:

    <attr  
        path="/api/package[@name='com.xxx.xxx']/class[@name='ListenerConsumer']/method[@name='setOnBListener']"   
        name="eventName">D</attr>  
    

    will produce in generated C# code D event.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.