Code Monkey home page Code Monkey logo

proxier's Introduction

MahApps.Metro

Proxier

GitHub license Twitter NuGet Build status

Introduction โ„น๏ธ

Have you ever had a class that is generated during the build process or at runtime but you need to add attributes to it? This is the solution! You can add attributes and even properties to classes at runtime by defining an extension class!

Features

  • ๐Ÿฑโ€๐Ÿ‘ค Out of the box support for Ninject!
  • ๐Ÿ•› 0 configuration time, just start using.
  • โ„น๏ธ Semantic extensions, easy to use.
  • .NET Core support

Code Samples โœ๏ธ

Say that you are using NSwag to generate swagger based classes, but they change a lot and you are worried that you forget to add some attributes to it and decide to use this library:

First you'll install the NuGet package

Install-Package Proxier

Then you'll create a extension class like so:

    public class MyClassExtension : AttributeMapper<MyClass> {
        public MyClassExtension(){
            //Here you can add any class attributes, properties attributes and even properties!
            AddPropertyAttribute(u => u.Business, () => new MyAttribute());
            AddProperty("MyProperty", typeof(string));
            AddClassAttribute(() => new MyAttribute());
        } 
    }

and then these properties will be added to a static mapper list, the Mapper.TypesOverrides with all the current extensions. To convert a object from the "MyClass" type to the injected type you would call:

typeof(MyClass).GetInjectedType();

To get a injected object you can use:

var InjectedMyClassObject = MyClassObject.GetInjectedObject();

Note that you can convert the inject object back to the original type by calling

InjectedMyClassObject.CopyTo(MyClassObject);

and all the common properties will be overriden by the ones on the injected type.

Dependency Injection

You can pass a Kernel to the Mapper initializer like this:

Mapper.InitializeMapperClasses(MyNinjectKernel);

and use the default [Inject] attribute from Ninject to get properties inside the extension class which in turn can add those into its current extended type.

Built With ๐Ÿ”ง

License ๐Ÿ“š

This project is licensed under the MIT License - see the LICENSE.md file for details

This documentation is incomplete and may change overtime.

proxier's People

Contributors

redbaty avatar

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.