2

有趣的是,在实现和不实现 IReturn 的情况下看到元显示的不同。实现 IReturn 后,我想知道如何构建 DTO 来修剪元数据输出?

在此处输入图像描述

代码

namespace Backbone.Todos {
//Without IReturn --------------------------
[Route("/todos","POST")] //add
[Route("/todos/{id}","POST")] //edit
public class Todo {
    public long Id { get; set; }
    public string Content { get; set; }
    public int Order { get; set; }
    public bool Done { get; set; }
}
//-----------------------------------------
[Route("/todos","GET")] //list
public class TodoList {
} 
//-----------------------------------------
[Route("/todos/{id}","DELETE")]//delete
public class DeleteTodo {
    public int Id { get; set; }
}
//-----------------------------------------
[Route("/todos/reset")] //reset
public class ResetTodos {
}

……

现在相同,但使用 IReturn<>,元数据看起来很奇怪。注意图中的 List`1 和双待办事项。

namespace Backbone.Todos {
//Implementing IReturn---------------------
[Route("/todos","POST")] //add
[Route("/todos/{id}","POST")] //edit
public class Todo : IReturn<Todo> {
    public long Id { get; set; }
    public string Content { get; set; }
    public int Order { get; set; }
    public bool Done { get; set; }
}
//-----------------------------------------
[Route("/todos","GET")] //list
public class TodoList : IReturn<List<Todo>>  {
} 
//-----------------------------------------
[Route("/todos/{id}","DELETE")]//delete
public class DeleteTodo : IReturnVoid {
    public int Id { get; set; }
}
//-----------------------------------------
[Route("/todos/reset")] //reset
public class ResetTodos : IReturnVoid{
}
//-----------------------------------------
......
4

1 回答 1

3

使用新 API 的元数据页面已经在 ServiceStack 的 HEAD 版本中修复。你现在可以 fork 存储库,否则新版本的 ServiceStack 会在周末部署。

于 2012-10-05T06:51:53.640 回答