GithubHelp home page GithubHelp logo

methodtodelegate's Introduction

MethodToDelegate

Create delegates from (partially applied) methods.

MethodToDelegate partners with your Dependency Injection framework to turn a MethodInfo object into a delegate type. It uses partially application on the first N arguments of your method that are not found in the delegate signature. For example, if your delegate has 3 parameters and your method has 5, the first 2 parameters will be supplied by depedency injection.

See the files in MethodToDelegate.Test/ for examples on how to set up delegate-based dependency injection on methods, how to wire them into your dependency injection framework, and how to run unit tests against your methods. Here are the basic instructions:

  1. Use the ToDelegate attribute to tag methods with the delegate type into which they should be converted. Then, use the following methods:

  2. DelegateHelper.GetDelegateTypesAndMethods(Type) takes a Type for a class, and returns the pair of delegate Type and MethodInfo for each public static method using the ToDelegate attribute.

  3. DelegateHelper.CreateBuildInfo and DelegateHelper.BuildDelegate together will take one of the outputs from DelegateHelper.GetDelegateTypesAndMethods, partially apply the method, and create the delegate. DelegateHelper.CreateBuildInfo can be done without needing your dependency injection framework (i.e. before all dependent types have been registered), whereas DelegateHelper.BuildDelegate requires access to your dependency injection framework (specifically how to go from Type to object of that type).

MethodToDelegate also provides extension methods for partial application - Func.Apply and Action.Apply, as well as extension methods for delegate Type conversion.

Extensions targeted for supporting Ninject can be found at MethodToDelegate.Ninject.

TODO: Support Generic Delegates

methodtodelegate's People

Contributors

willryan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.