Coder Social home page Coder Social logo

panoukos41 / viewbindingsgenerator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 101 KB

A project that generates a partial class (view) for Activities/Fragments that will contain properties with the same name as their android:id in the xml view file.

License: MIT License

C# 100.00%

viewbindingsgenerator's Introduction

ViewBindingsGenerator

Release NuGet MIT License

A project that generates a partial class (view) for Activities/Fragments that will contain properties with the same name as their android:id in the xml view file.

Getting Started

Add the following property to your csproj inside an ItemGroup

<AdditionalFiles Include="Resources\layout\*.xml" OutputType="Analyzer" />

Then make your activity or fragment partial and add the [GenerateBindings("view_file.xml")] attribute.

Activity

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
[AndroidBinding("activity_main.xml")]
public partial class MainActivity : AppCompatActivity
{
    protected override void OnCreate(Bundle? savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_main);
    }
}

Fragment

[AndroidBinding("fragment_main.xml")]
public partial class MainFragment : Fragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.Inflate(Resource.Layout.fragment_main, container, false)!;
    }
}

Build

Install Visual Studio 2022 Preview and .NET 6.0

Clone the project and open the solution then you just build the whole solution or project.

Contribute

Contributions are welcome and appreciated, before you create a pull request please open a GitHub Issue to discuss what needs changing and or fixing if the issue doesn't exist!

Credits

This library was created by reading some posts from Andrew Lock like this or this and by observing how the jab project was coded.

The posts are great plus there are a lot more to read and jab is a really great library, you should check them out!

viewbindingsgenerator's People

Contributors

panoukos41 avatar

Watchers

 avatar

Forkers

wangkai2014

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.