title: Need help porting Java to C# - How to handle anonymous inner class?
body: <p>I've looked at some of the other answers regarding the java inner anonymous class, but I am looking for something specific to the Xamarin implementation of C#.</p>
  
  <p>I am working to move the openCamera project (<a href="http://opencamera.sourceforge.net/" rel="nofollow">http://opencamera.sourceforge.net/</a>) from java to C# in Xamarin.</p>
  
  <p>I am struggling to figure out the best way of handling the anonymous inner class of java.</p>
  
  <p>The Java code snippet (one of many) I am working on is this:</p>
  
  <pre><code>    orientationEventListener = new OrientationEventListener(this) {
          @Override
          public void onOrientationChanged(int orientation) {
              MainActivity.this.onOrientationChanged(orientation);
          }
      };
  </code></pre>
  
  <p>How is that best expressed in Xamarin recognized C# code?</p>
  
  <p>If I use Tangible Software's Java to C# program, it creates a helper class called "OrientationEventListenerAnonymousInnerClassHelper" -- which is cool -- unfortunately, it doesn't compile. I'm happy to hand code this, but there must be a slick way of doing it that escapes me. As I said, I'm going to have a lot of them.</p>
  
  <p>The code Tangible Software produces looks like this:</p>
  
  <p>First it declares it with a using statement like this:</p>
  
  <pre><code>using OrientationEventListener = android.view.OrientationEventListener;
  </code></pre>
  
  <p>Then it creates this to handle the anonymous inner class:</p>
  
  <pre><code>private class OrientationEventListenerAnonymousInnerClassHelper : OrientationEventListener
  {
      private readonly MainActivity outerInstance;
  
      public OrientationEventListenerAnonymousInnerClassHelper(MainActivity outerInstance, net.opencamera.MainActivity this) : base(this)
      {
          this.outerInstance = outerInstance;
      }
  
      public override void onOrientationChanged(int orientation)
      {
          outerInstance.onOrientationChanged(orientation);
      }
  }
  </code></pre>
  
  <p>The Xamarin studio complains about the use of <code>net.opencamera.MainActivity this</code>, FWIW. </p>
  
  <p>Since Java programmers love their anonymous inner classes, I'm going to have a lot of these to work through. What is the best practice for this?</p>
  
  <p>Thanks!</p>