我有一个curried的typed-Lambda表达式,我希望它能执行选择并派生出一个独特的元素。可悲的是,有一个运行时例外。
以下是代码:
Entities relation = queryType(
"test-instances",
(new KeyValuePair<String, String>("cycle-id", testSetID))
);
Entity target = (relation.entities.ToList<Entity>()).Find(
//select entity with field 'name'
e => (e.fields.Find(
//and with non-epsillon value
f => !(f.values.Find(
//of value 'targetValue'
v => (v.value.Equals(targetValue))
).value.Equals(""))
)).name.Equals("name")
);
queryType()
的定义:
private Entities queryType(String entitiesType, params KeyValuePair<String, String>[] values)
{
addStandardHeaders();
String query = parsePredicate(values);
Task<HttpResponseMessage> filterTask = client.GetAsync(client.BaseAddress + RESTapi.ALMentitiesQuery(domain, project, entitiesType, query));
Task.WaitAny(filterTask);
//Callback:
HttpResponseMessage result = filterTask.Result;
if (result.IsSuccessStatusCode)
{
updateCookies(client.BaseAddress + RESTapi.ALMentitiesQuery(domain, project, entitiesType, query));
mainHeaders.Clear();
Task<Stream> output = result.Content.ReadAsStreamAsync();
Task.WaitAny(output);
//Callback:
return (Entities)fromJSON(output.Result, typeof(Entities));
}
else
{
Exception exception = getException(result);
throw new HttpException(exception.Title);
return null;
}
}
函数parsePredicate()
接受pairs()并将它们编码为服务器理解的语言的谓词。
例外是在最内层的功能;绑定变量v
应用为null
。 e
到f
可以使用,我使用的数据模型也很合理。
有什么想法吗?
以下是Entities
的课程:
public class Entities
{
public List<Entity> entities{get;set;}
public long totalResults{get;set;}
public Entities(){entities = new List<Entity>();}
}
public class Entity
{
public List<Field> fields { get; set; }
public Entity() { fields = new List<Field>(); }
}
public class Field
{
public String name { get; set; }
public List<Value> values { get; set; }
public Field() { values = new List<Value>(); }
}
public class Value
{
public String value{get;set;}
}