有趣的是,在实现和不实现 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{
}
//-----------------------------------------
......