public LspHandlerTypeDescriptor(Type handlerType) : base(handlerType) { PartialItemsType = ParamsType.GetInterfaces().FirstOrDefault(z => z.IsGenericType && typeof(IPartialItems <>).IsAssignableFrom(z.GetGenericTypeDefinition())) ?.GetGenericArguments()[0]; HasPartialItems = PartialItemsType != null; PartialItemType = ParamsType.GetInterfaces().FirstOrDefault(z => z.IsGenericType && typeof(IPartialItem <>).IsAssignableFrom(z.GetGenericTypeDefinition())) ?.GetGenericArguments()[0]; HasPartialItem = PartialItemType != null; RegistrationType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(IRegistration <>), handlerType); HasRegistration = RegistrationType != null && RegistrationType != typeof(object); if (!HasRegistration) { RegistrationType = null; } CapabilityType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(ICapability <>), handlerType); HasCapability = CapabilityType != null; if (!HasCapability) { CapabilityType = null; } if (HasCapability) { IsDynamicCapability = typeof(IDynamicCapability).GetTypeInfo().IsAssignableFrom(CapabilityType); } }
/// <summary> /// Http请求 /// </summary> /// <param name="rootURL">请求地址</param> /// <param name="ParamsType">参数类型</param> /// <param name="queryParams">地址栏参数</param> /// <param name="bodyParamStr">Body参数 可为Json/Text</param> /// <param name="encoding">URL解码编码</param> /// <param name="netType">POST/GET</param> /// <param name="Charset">Http编码规范</param> /// <param name="contentType">请求体类型</param> /// <returns></returns> public static string HttpReq(string rootURL, ParamsType paramsType, string bodyParamStr, Encoding encoding, NetType netType, ContentType contentType, Charset charset, IDictionary queryParams = null) { string result = string.Empty; HttpWebRequest req = null; switch (paramsType) { case ParamsType.Header: req = (HttpWebRequest)WebRequest.Create($"{rootURL}"); req.Headers.Add(GetWebHeaderCollection(queryParams)); break; case ParamsType.QueryParams: req = (HttpWebRequest)WebRequest.Create($"{rootURL}?{KeyValueHandle(queryParams)}"); break; case ParamsType.NoParams: req = (HttpWebRequest)WebRequest.Create($"{rootURL}"); break; default: break; } req.Method = GetNetType(netType); if (charset == Charset.UTF_8) { req.ContentType = $"{GetContentType(contentType)}{"utf-8"}"; } else { req.ContentType = $"{GetContentType(contentType)}{charset}"; } #region 添加Post 参数 if (netType == NetType.POST) { byte[] data = encoding.GetBytes(bodyParamStr); req.ContentLength = data.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } } #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } if (resp != null) { resp.Close(); } GC.Collect(); //URL转码 return(System.Web.HttpUtility.UrlDecode(result, encoding)); }
/// <summary> /// 初始化 /// </summary> /// <param name="name"></param> /// <param name="dataType"></param> /// <param name="direction"></param> /// <param name="value"></param> /// <param name="size">默认500,根据自己需求来改变 public SqlHelperParameter(string name, ParamsType dataType, ParameterDirection direction, object value, int size = 500) { this.Name = name; this.DataType = dataType; this.Direction = direction; this.Value = value; this.Size = size; }
public HandlerTypeDescriptor(Type handlerType) { var method = MethodAttribute.From(handlerType) !; Method = method.Method; Direction = method.Direction; if (handlerType.IsGenericTypeDefinition && handlerType.IsPublic) { var parameter = handlerType.GetTypeInfo().GenericTypeParameters[0]; var constraints = parameter.GetGenericParameterConstraints(); if (constraints.Length == 1) { handlerType = handlerType.MakeGenericType(handlerType.GetTypeInfo().GenericTypeParameters[0].GetGenericParameterConstraints()[0]); } } HandlerType = handlerType; InterfaceType = HandlerTypeDescriptorHelper.GetHandlerInterface(handlerType); // This allows for us to have derived types // We are making the assumption that interface given here // if a GTD will have a constraint on the first generic type parameter // that is the real base type for this interface. if (InterfaceType.IsGenericType) { ParamsType = InterfaceType.GetGenericArguments()[0]; } HasParamsType = ParamsType != null; IsNotification = handlerType .GetInterfaces() .Any(z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom(z.GetGenericTypeDefinition())); IsRequest = !IsNotification; var requestInterface = ParamsType? .GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)); if (requestInterface != null) { ResponseType = requestInterface.GetGenericArguments()[0]; } HasResponseType = ResponseType != null && ResponseType != typeof(Unit); var processAttributes = HandlerType .GetCustomAttributes(true) .Concat(HandlerType.GetCustomAttributes(true)) .Concat(InterfaceType.GetInterfaces().SelectMany(x => x.GetCustomAttributes(true))) .Concat(HandlerType.GetInterfaces().SelectMany(x => x.GetCustomAttributes(true))) .OfType <ProcessAttribute>() .ToArray(); RequestProcessType = processAttributes .FirstOrDefault()?.Type; }
public HandlerTypeDescriptor(Type handlerType) { var method = handlerType.GetCustomAttribute <MethodAttribute>(); Method = method.Method; Direction = method.Direction; HandlerType = handlerType; InterfaceType = HandlerTypeDescriptorHelper.GetHandlerInterface(handlerType); ParamsType = InterfaceType.IsGenericType ? InterfaceType.GetGenericArguments()[0] : typeof(EmptyRequest); HasParamsType = ParamsType != null && ParamsType != typeof(EmptyRequest); IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerType) || handlerType .GetInterfaces().Any(z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom(z.GetGenericTypeDefinition())); IsRequest = !IsNotification; var requestInterface = ParamsType? .GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)); if (requestInterface != null) { ResponseType = requestInterface.GetGenericArguments()[0]; } HasResponseType = ResponseType != null && ResponseType != typeof(Unit); var processAttributes = HandlerType .GetCustomAttributes(true) .Concat(HandlerType.GetCustomAttributes(true)) .Concat(InterfaceType.GetInterfaces().SelectMany(x => x.GetCustomAttributes(true))) .Concat(HandlerType.GetInterfaces().SelectMany(x => x.GetCustomAttributes(true))) .OfType <ProcessAttribute>() .ToArray(); RequestProcessType = processAttributes .FirstOrDefault()?.Type; }
public Presenter_params(IView_params iwg, ParamsType type) { this.type = type; _view = iwg; _view.ReturnParams += new EventHandler <EventArgs>(Params); }
public RequestParams(ParamsType paramType) { m_paramType = paramType; }
public ParamUnit(ParamsType _paramType, float stat) : this(stat) { ParamType = _paramType; }