Skip to content

Static interface to dynamic implementation (duck casting). That and more using the DLR.

License

Notifications You must be signed in to change notification settings

pedoc/impromptu-interface

 
 

Repository files navigation

net4.0/netstd2.0 framework to allow you to wrap any object (static or dynamic) with a static interface even though it didn't inherit from it. It does this by emitting cached dynamic binding code inside a proxy.

ImpromptuInterface is available Nuget NuGet

You can find the latest bleed edge on MyGet MyGet Pre Release

Platofrm Status
Windows Build status
Mac Build Status
Linux Build Status

Some of the features of ImpromptuInterface have been moved into another library called Dynamitey, ImpromptuInterface depends on Dynamitey.

ImpromptuInterface.FSharp has been spun off into FSharp.Interop.Dynamic and also depends on Dynamitey.

ImpromptuInterface.MVVM only exists for ImpromptuInterface 6.X and earlier.

Quick Usage:

    using ImpromptuInterface;
    using Dynamitey;

    public interface IMyInterface{

       string Prop1 { get;  }

        long Prop2 { get; }

        Guid Prop3 { get; }

        bool Meth1(int x);
   }
   //Anonymous Class
    var anon = new {
             Prop1 = "Test",
             Prop2 = 42L,
             Prop3 = Guid.NewGuid(),
             Meth1 = Return<bool>.Arguments<int>(it => it > 5)
    }

    var myInterface = anon.ActLike<IMyInterface>();

OR

   //Dynamic Expando object
    dynamic expando = new ExpandoObject();
    expando.Prop1 ="Test";
    expando.Prop2 = 42L;
    expando.Prop3 = Guid.NewGuid();
    expando.Meth1 = Return<bool>.Arguments<int>(it => it > 5);
    IMyInterface myInterface = Impromptu.ActLike(expando);

About

Static interface to dynamic implementation (duck casting). That and more using the DLR.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.8%
  • Shell 0.2%