Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
MAX POLKOVNIK edited this page Mar 23, 2018 · 7 revisions

Answer is very simple. This project uses Fody for weaving output assembly.

In every file which contains class members marked with [View], [MenuItem], [ViewEvent] will be generated method to resolve or bind members.

Example

Before injecting

[Activity(Label = "TestActivity")]
public class TestActivity : Activity
{
    [View] private Button _myButton { get; }

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.screen_test);

        Injector.InjectViews();

        _myButton.SetBackgroundColor(Color.AliceBlue);
    }
}

After injecting:

[Activity(Label = "TestActivity")]
public class TestActivity : Activity
{
  [View] private Button _myButton { get; set; }

  protected virtual void OnCreate(Bundle savedInstanceState)
  {
    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.screen_test);
    Polkovnik_DroidInjector_InjectViews(Polkovnik_DroidInjector_GetRootView());
    _myButton.SetBackgroundColor(Color.AliceBlue);
  }

  private void Polkovnik_DroidInjector_InjectViews(View view)
  {
    Button viewById = (Button) view.FindViewById(Resource.Id.myButton);
    if (viewById == null)
        throw new InjectorException("Can't find view for Android.Widget.Button Polkovnik.DroidInjector.FodyClassLibrarySample.TestActivity::_myButton()");
    _myButton = viewById;
  }

  private View Polkovnik_DroidInjector_GetRootView()
  {
    return FindViewById(16908290);
  }
}

No magic, no reflection...

Check out speed comparsion

Clone this wiki locally