title: Using a locally defined class instead of the one provided by a library/package C# IL Weaving
body: <p>I have seen stuff like <a href="https://github.com/Fody/Fody" rel="nofollow noreferrer">Fody</a> and in fact have been using <a href="https://github.com/Fody/PropertyChanged" rel="nofollow noreferrer">PropertyChanged</a> which reduces the boilerplate code after implementing the INotifyPropertyChanged interface.</p>
  <p>I believe it is done by 'weaving the IL' so an idea crossed my mind.</p>
  <p>The problem is that I am trying to define my own version of a class and use it instead of the one defined in a nuget package. This is because the library one deals with a TextView whereas I would like it to deal with an AppCompatTextView instead.</p>
  <p>AppCompatTextView is:</p>
  <pre><code>public class AppCompatTextView : 
      TextView,
      IEmojiCompatConfigurationView,
      IJavaObject,
      IDisposable,
      IJavaPeerable,
      ITintableBackgroundView,
      IAutoSizeableTextView,
      ITintableCompoundDrawablesView
  </code></pre>
  <p>As you can see, AppCompatTextView inherits from TextView and this should make things easier.</p>
  <p>By default, the library (Xamarin.Forms) has defined a LabelRenderer as:</p>
  <pre><code>public class LabelRenderer : FormsTextView, IVisualElementRenderer, IViewRenderer, ITabStop
  </code></pre>
  <p>Where:</p>
  <pre><code>namespace Xamarin.Forms.Platform.Android
  {
      public class FormsTextView : TextView
      {
          public FormsTextView(Context context) : base(context)
          {
          }
  
          [Obsolete]
          public FormsTextView(Context context, IAttributeSet attrs) : base(context, attrs)
          {
          }
  
          [Obsolete]
          public FormsTextView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
          {
          }
  
          [Obsolete]
          protected FormsTextView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
          {
          }
  
          [Obsolete]
          public void SkipNextInvalidate()
          {
          }
      }
  }
  </code></pre>
  <p>However, I would like to create my own version of LabelRenderer which inherits from AppCompatTextView instead.</p>
  <p>This is to meet the requirements outlined by <a href="https://developer.android.com/guide/topics/ui/look-and-feel/emoji2#custom-views-appcompat" rel="nofollow noreferrer">Google to display modern emojis</a></p>
  <p>When seeing the code for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer, we can see that:</p>
  <pre><code>protected global::Android.Widget.TextView Control =&gt; this;
  </code></pre>
  <p>The idea that came to my mind was that would it be possible to use some IL Weaving tool so that it would be this instead:</p>
  <pre><code>protected global::AndroidX.AppCompat.Widget.AppCompatTextView Control =&gt; this;
  </code></pre>
  <p>In other words, would it be possible to 'weave the IL' in a way that when it wants to load this IL:</p>
  <pre><code>  .property instance class [Mono.Android]Android.Widget.TextView Control()
    {
      .get instance class [Mono.Android]Android.Widget.TextView Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::get_Control()
    } 
  </code></pre>
  <p>It should be an AndroidX.AppCompat.Widget.AppCompatTextView instead of Android.Widget.TextView:</p>
  <pre><code>.property instance class [Mono.Android]AndroidX.AppCompat.Widget.AppCompatTextView Control()
    {
      .get instance class [Mono.Android]AndroidX.AppCompat.Widget.AppCompatTextView Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::get_Control()
    } // end of property LabelRenderer::Control
  </code></pre>
  <p>Thanks!</p>