https://github.com/ekonbenefits/impromptu-interface
Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit.
https://github.com/ekonbenefits/impromptu-interface
Last synced: 3 months ago
JSON representation
Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit.
- Host: GitHub
- URL: https://github.com/ekonbenefits/impromptu-interface
- Owner: ekonbenefits
- License: apache-2.0
- Created: 2012-08-27T12:46:40.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T14:24:48.000Z (over 1 year ago)
- Last Synced: 2024-10-01T07:24:11.181Z (9 months ago)
- Language: C#
- Homepage:
- Size: 2.49 MB
- Stars: 656
- Watchers: 35
- Forks: 67
- Open Issues: 20
-
Metadata Files:
- Readme: Readme.md
- License: License.txt
Awesome Lists containing this project
- awesome-dotnet-core - impromptu-interface - Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit. (Frameworks, Libraries and Tools / Misc)
- awesome-dotnet-core - impromptu-interface - 将DLR与Reflect.Emit结合使用的库。 (框架, 库和工具 / 大杂烩)
- fucking-awesome-dotnet-core - impromptu-interface - Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit. (Frameworks, Libraries and Tools / Misc)
- awesome-dotnet-core - impromptu-interface - Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit. (Frameworks, Libraries and Tools / Misc)
README
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 [](https://www.nuget.org/packages/ImpromptuInterface/)
Platform | Status
-------- | ------
NET4 (Win) | [](https://github.com/ekonbenefits/impromptu-interface/actions/workflows/dotnet48.yml?query=branch%3Amaster)
NETSTD (Win/Mac/Linux) | [](https://github.com/ekonbenefits/impromptu-interface/actions/workflows/dotnet.yml?query=branch%3Amaster)
Some of the features of `ImpromptuInterface` have been moved into another library called [Dynamitey](https://github.com/ekonbenefits/dynamitey), `ImpromptuInterface` depends on `Dynamitey`.
`ImpromptuInterface.FSharp` has been spun off into [FSharp.Interop.Dynamic](https://github.com/fsprojects/FSharp.Interop.Dynamic) and also depends on `Dynamitey`.
`ImpromptuInterface.MVVM` has been spun off into it's own repo [ImpromptuInterface.MVVM](https://github.com/ekonbenefits/impromptu-interface.mvvm) and only receives maitenance updates.
### Quick Usage:
```csharp
using ImpromptuInterface;
using Dynamitey;public interface IMyInterface{
string Prop1 { get; }
long Prop2 { get; }
Guid Prop3 { get; }
bool Meth1(int x);
}```
```csharp
//Anonymous Class
var anon = new {
Prop1 = "Test",
Prop2 = 42L,
Prop3 = Guid.NewGuid(),
Meth1 = Return.Arguments(it => it > 5)
};var myInterface = anon.ActLike();
```## OR
```csharp
//Dynamic Expando object
dynamic expando = new ExpandoObject();
expando.Prop1 ="Test";
expando.Prop2 = 42L;
expando.Prop3 = Guid.NewGuid();
expando.Meth1 = Return.Arguments(it => it > 5);
IMyInterface myInterface = Impromptu.ActLike(expando);
```