private bool PresumePathParaBind() { if (false == this.MethodWrap.NeedPathPara(this.Parameter.Name)) { return(false); } PathParaBind paraBind; if (TypeReflector.IsPrivateValue(this.Parameter.ParameterType)) { paraBind = this.MethodWrap.GetPathParaBind(this.Parameter.Name); if (paraBind == null) { paraBind = new PathParaBind(this.Parameter.Name); this.PathParaBindes.Add(paraBind); return(true); } else { return(false); } } else { return(false); } }
private bool PresumeQueryStringBind() { QueryStringBind queryStringBind; List <FieldInfo> fieldInfos = new List <FieldInfo>(this.Parameter.ParameterType.GetFields()); List <PropertyInfo> properties = new List <PropertyInfo>(this.Parameter.ParameterType.GetProperties()); if (this.MethodWrap.IsGet()) { if (TypeReflector.IsPrivateValue(this.Parameter.ParameterType)) { queryStringBind = new QueryStringBind(this.Parameter.Name); this.QueryStringBindes.Add(queryStringBind); return(true); } else { fieldInfos.ForEach(f => { queryStringBind = new QueryStringBind(f.Name, f); this.QueryStringBindes.Add(queryStringBind); }); properties.ForEach(p => { queryStringBind = new QueryStringBind(p.Name, p); this.QueryStringBindes.Add(queryStringBind); }); return(true); } } if (this.MethodWrap.IsPOST()) { return(false); } return(false); }
internal void AddParameterQueryString(RequestCreContext requestCreContext, ParameterWrapContext parameterWrap) { HttpContent httpContext = requestCreContext.httpRequestMessage.Content; object paraValue = requestCreContext.ParameterValues.Value[parameterWrap.Parameter.Position]; if (TypeReflector.IsPrivateValue(parameterWrap.Parameter.ParameterType)) { //todo valueStr :performance problem ? string valueStr = parameterWrap.Serial(paraValue); parameterWrap.QueryString = this.Name + "=" + valueStr; requestCreContext.QueryString.Add(this.Name, valueStr); } else { if (Field == null && Property == null) { string valueStr = parameterWrap.Serial(paraValue); parameterWrap.QueryString = this.Name + "=" + valueStr; requestCreContext.QueryString.Add(this.Name, valueStr); } else { object value; string queryName = null; if (Field != null) { queryName = Field.Name; value = Field.GetValue(paraValue); } else if (Property != null) { queryName = Property.Name; value = Property.GetValue(paraValue); } else { throw new SystemException(nameof(this.Name)); } string valueStr = parameterWrap.Serial(value); parameterWrap.QueryString = queryName + "=" + valueStr; requestCreContext.QueryString.Add(queryName, valueStr); } } }
private void BindAttribute() { PathParaBind paraBind; ParameterHeaderBind headerBind; QueryStringBind queryStringBind; string headername; List <FieldInfo> fieldInfos = new List <FieldInfo>(this.Parameter.ParameterType.GetFields()); List <PropertyInfo> properties = new List <PropertyInfo>(this.Parameter.ParameterType.GetProperties()); if (this.pathParaAttribute != null) { paraBind = new PathParaBind(string.IsNullOrEmpty(pathParaAttribute.Name) ? this.Parameter.Name : pathParaAttribute.Name); paraBind.Prompt(); this.PathParaBindes.Add(paraBind); AttributeBinded = true; } if (this.HeaderAttributes.Count > 0) { this.HeaderAttributes.ForEach(x => { if (TypeReflector.IsPrivateValue(this.Parameter.ParameterType)) { headername = string.IsNullOrEmpty(x.Name) ? this.Parameter.Name : x.Name; headerBind = new ParameterHeaderBind(this, headername, x.Unique); headerBind.Prompt(); this.HeaderBindes.Add(headerBind); } else { fieldInfos.ForEach(f => { headerBind = new ParameterHeaderBind(this, f.Name, f, x.Unique); headerBind.Prompt(); this.HeaderBindes.Add(headerBind); }); properties.ForEach(p => { headerBind = new ParameterHeaderBind(this, p.Name, p, x.Unique); headerBind.Prompt(); this.HeaderBindes.Add(headerBind); }); } }); AttributeBinded = true; } if (this.QueryStringAttribute != null) { string queryname; if (TypeReflector.IsPrivateValue(this.Parameter.ParameterType)) { queryname = string.IsNullOrEmpty(this.QueryStringAttribute.Name) ? this.Parameter.Name : this.QueryStringAttribute.Name; queryStringBind = new QueryStringBind(queryname); queryStringBind.Prompt(); this.QueryStringBindes.Add(queryStringBind); } else { if (false == string.IsNullOrEmpty(this.QueryStringAttribute.Name)) { queryStringBind = new QueryStringBind(this.QueryStringAttribute.Name); queryStringBind.Prompt(); this.QueryStringBindes.Add(queryStringBind); } else { fieldInfos.ForEach(f => { queryStringBind = new QueryStringBind(f.Name, f); queryStringBind.Prompt(); this.QueryStringBindes.Add(queryStringBind); }); properties.ForEach(p => { queryStringBind = new QueryStringBind(p.Name, p); queryStringBind.Prompt(); this.QueryStringBindes.Add(queryStringBind); }); } } AttributeBinded = true; } }