Git Product home page Git Product logo

biind's Introduction

Biind

Version Downloads

Bind classes to interfaces, enabling more polymorphic inheritence and extensability of code you don't own, or making using legacy code slightly more enjoyable.

PM> Package-Install Biind

Examples

Two different classes to the same interface

public class A
{
    public int MyValue { get; set; }
}

public class B
{
    public int StoredValue { get; set; }
}

public interface IIntegerValue
{
    int Value { get; set; }
}

public Bind<A, IIntegerValue> MakeABinder(BindAssembly bindAssembly)
	=> new BindOptions<A, IIntegerValue>()
	.MapProperty(e => e.MyValue, e => e.Value)
	.Build(bindAssembly);

public Bind<B, IIntegerValue> MakeBBinder(BindAssembly bindAssembly)
	=> new BindOptions<B, IIntegerValue>()
	.MapProperty(e => e.StoredValue, e => e.Value)
	.Build(bindAssembly);

public void BindingTest()
{
	var assembly = new BindAssembly();

	var aBinder = MakeABinder(assembly);
	var bBinder = MakeBBinder(assembly);

	var a = new A();
	var b = new B();

	a.MyValue = 8;
	b.StoredValue = 4;

	var boundA = aBinder.NewBind(a);
	var boundB = bBinder.NewBind(b);

	Console.WriteLine(boundA.Value); // 8
	Console.WriteLine(boundB.Value); // 4

	boundA.Value = 6;
	boundB.Value = 6;

	Console.WriteLine(a.MyValue); // 6
	Console.WriteLine(b.StoredValue); // 6
}

Binding Console to an interface

public interface ILogger
{
    void WriteLine(string message);
    
    void Write(string message);
}

public ILogger MakeConsole(BindAssembly bindAssembly)
{
    return new BindOptions<object, ILogger>()
        .MapMethod(() => Console.WriteLine(default(string)), e => e.WriteLine(default(string)))
        .MapMethod(() => Console.Write(default(string)), e => e.Write(default(string)))
        .Build(bindAssembly)
        .NewBind(null);
}

var console = MakeConsole(new BindAssembly());

biind's People

Stargazers

etheaven avatar  avatar Erin Loy avatar Felipe Martínez avatar

Watchers

James Cloos avatar monoclex 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.