public void CtorTest() { var value = "name"; var name = LambdaUtil.CreateCtorFunc <string, Model>(typeof(Model))(value).name; Assert.True(name == value); var func = LambdaUtil.CreateCtorFunc <string, object>(typeof(Model)); var model = func.Invoke(value) as Model; Assert.True(model.name == value); }
/// <summary> /// 创建实例工厂 /// </summary> /// <exception cref="ProxyTypeCreateException"></exception> /// <returns></returns> protected override Func <IHttpApiInterceptor, ApiActionInvoker[], THttpApi> CreateFactory() { var proxyType = FindProxyType(typeof(THttpApi)); if (proxyType != null) { return(LambdaUtil.CreateCtorFunc <IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyType)); } var message = $"找不到{typeof(THttpApi)}的代理类:{GetErrorReason()}"; throw new ProxyTypeCreateException(typeof(THttpApi), message); }
/// <summary> /// 创建实例工厂 /// </summary> /// <exception cref="NotSupportedException"></exception> /// <exception cref="ProxyTypeCreateException"></exception> /// <returns></returns> protected override Func <IHttpApiInterceptor, ApiActionInvoker[], THttpApi> CreateFactory() { var proxyType = BuildProxyType(typeof(THttpApi), this.ApiMethods); return(LambdaUtil.CreateCtorFunc <IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyType)); }