Forum Xamarin Xamarin.Android

How to override in a specific instance

bunglerbungler Member
edited June 2019 in Xamarin.Android

Perhaps I don't know how to find what I'm looking for because I don't know what this process is called. I've included a permissions manager to my Xamarin Android app: github.com/karanchuri/PermissionManager

In the instructions, it says to override the methods in the manager class as such:
permission = new PermissionManager() {
@Override
public void ifCancelledAndCanRequest(Activity activity) {
[...]
}

@Override
public void ifCancelledAndCannotRequest(Activity activity) {
[...]
}

[...]
};

As you can tell, it's not like your every day override, and I don't know what to call this, so I can't find examples of how to correctly convert this to C# in my Xamarin project. It's overriding the PermissionManager at the point of instantiation. Can someone please point me in a good direction or link me to a place where I can find info on this type of override?

I'm sorry the formatting of this is bad; the editor won't format the code correctly if used normally between 2 ticks...

Tagged:

Best Answer

  • bunglerbungler Member
    Accepted Answer

    Well, apparently no one knows or cares :smile: But, in case you do, I found a solution and present it here for public edification.
    I ended up installing a tool called "Java to C# Converter" (Tangible Software Solutions). I plugged in the following:

    permission = new PermissionManager() {
        @Override 
        public void ifCancelledAndCanRequest(Activity activity) { 
            [...] 
        } 
    
        @Override 
        public void ifCancelledAndCannotRequest(Activity activity) {
            [...] 
        } 
    
        [...]
    };
    

    ... and it spit out this:

    permission = new PermissionManagerAnonymousInnerClass();
    private class PermissionManagerAnonymousInnerClass : PermissionManager
    {
        public override void ifCancelledAndCanRequest(Activity activity) {
            [...]
        }
    
        public override void ifCancelledAndCannotRequest(Activity activity)
        {
            [...]
        }
    
        [...]
    };
    

Answers

  • bunglerbungler Member
    Accepted Answer

    Well, apparently no one knows or cares :smile: But, in case you do, I found a solution and present it here for public edification.
    I ended up installing a tool called "Java to C# Converter" (Tangible Software Solutions). I plugged in the following:

    permission = new PermissionManager() {
        @Override 
        public void ifCancelledAndCanRequest(Activity activity) { 
            [...] 
        } 
    
        @Override 
        public void ifCancelledAndCannotRequest(Activity activity) {
            [...] 
        } 
    
        [...]
    };
    

    ... and it spit out this:

    permission = new PermissionManagerAnonymousInnerClass();
    private class PermissionManagerAnonymousInnerClass : PermissionManager
    {
        public override void ifCancelledAndCanRequest(Activity activity) {
            [...]
        }
    
        public override void ifCancelledAndCannotRequest(Activity activity)
        {
            [...]
        }
    
        [...]
    };
    
Sign In or Register to comment.