public override bool TryResolve(string name, out object value) { FastProperty prop = _reflection.GetGetter(name); if (null != prop) { value = prop.GetValue(_params); return(true); } else { value = null; return(false); } }
protected virtual internal HttpResponseMessage UnmappedGetProperty(ODataPath odataPath) { int key; if (!odataPath.GetNormalizedKey(1, out key)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, WebApiGlobal.Error.NoKeyFromPath)); } var entity = GetEntityByKey(key); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, WebApiGlobal.Error.EntityNotFound.FormatInvariant(key))); } FastProperty prop = null; string propertyName = null; var lastSegment = odataPath.Segments.Last(); var propertySegment = (lastSegment as PropertyAccessPathSegment); if (propertySegment == null) { propertyName = lastSegment.ToString(); } else { propertyName = propertySegment.PropertyName; } if (propertyName.HasValue()) { prop = FastProperty.GetProperty(entity.GetType(), propertyName); } if (prop == null) { return(UnmappedGetProperty(entity, propertyName ?? "")); } var propertyValue = prop.GetValue(entity); return(Request.CreateResponse(HttpStatusCode.OK, prop.Property.PropertyType, propertyValue)); }
public override bool TryResolve(string name, out object value) { //这里传入的name是字段名,根据字段名找到映射的属性 FastProperty prop = _mapping.GetMappingProperty(name); //如果参数是实体对象,直接返回属性的值 if (null != prop && _sqlParams.IsObjectParameters() && prop.Info.DeclaringType.IsInstanceOfType(_rawParams)) { value = prop.GetValue(_rawParams); return(true); } //先找字段名 if (!_sqlParams.TryResolve(name, out value)) { //再找属性名 if (null != prop && !prop.Name.Equals(name)) { return(_sqlParams.TryResolve(prop.Name, out value)); } return(false); } return(true); }