我正在尝试为 Nancy POST 设置路由,我希望在其中提交 Json 格式的对象,并使用它来触发 Unity 运行时中的事件——我认为这应该是相当标准的东西。
我认为通过遵循NancyFX 中的示例:反序列化 JSON,我将能够将请求的主体绑定到一个对象,然后在其他地方使用它,但是我实际上遇到了这个相当神秘的错误:
Error CS1061: Type 'server.RESTServer' does not contain a definition for 'Bind' and no extension method 'Bind' of type 'server.RESTServer' could be found (are you missing a using directive or an assembly reference?) (CS1061) (server)
这是来自违规来源的相关部分:
using Nancy;
namespace server
{
public class RESTServer : Nancy.NancyModule, RESTInterface
{
public class LevelInfo
{
public string index;
}
public RESTServer ()
{
Delete ["/current/level"] = _ =>
{
UnloadLevel();
return HttpStatusCode.OK;
};
Get ["/current/level"] = _ => Level;
Post ["/current/level"] = _ =>
{
LevelInfo body = this.Bind<LevelInfo>(); //This is the offending line
// snip rest of implementation
}
}
}
}
我的 Mono/Monodevelop 版本信息在此处的 pastebin 上,Assembly Browser为 Nancy显示了这一点,也链接在 pastebin 上。
我通常不做太多的.net开发,所以我确信这很简单,但我已经失去了一个下午试图解决这个问题......任何帮助将不胜感激。