轻量级动态框架 ImpromptuInterface
使用NuGet包安装ImpromptuInterface 一个轻量级的C#动态框架。ImpromptuInterface轻松将动态对象和接口绑定起来,从而直接利用接口中提供的属性和方法。使用示例程序:
namespace ImpromptuExample {class Program {static void Main(string[] args) {dynamic expando = new ExpandoObject();expando.Name = "Albert";expando.Age = "24";expando.GetAge = (Func<int>)(() => { return 24; });expando.Prop1 = "WPF";//Improptu.ActLike动态实现继承接口的对象IMyInterface myInterface = Impromptu.ActLike(expando);Console.WriteLine(expando.Age);Console.WriteLine(expando.GetAge);Console.WriteLine(myInterface.Prop1);Console.ReadLine();}}public interface IMyInterface {string Prop1 { get; }long Prop2 { get; }Guid Prop3 { get; }bool Meth1(int x);}}
