鼎鼎知识库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7、Hi,建造者模式.md 970B

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ```
  2. public class ToDoItemBuilder
  3. {
  4. private ToDoItem _todo = new ToDoItem();
  5. public ToDoItemBuilder Id(int id)
  6. {
  7. _todo.Id = id;
  8. return this;
  9. }
  10. public ToDoItemBuilder Title(string title)
  11. {
  12. _todo.Title = title;
  13. return this;
  14. }
  15. public ToDoItemBuilder Description(string description)
  16. {
  17. _todo.Description = description;
  18. return this;
  19. }
  20. public ToDoItemBuilder WithDefaultValues()
  21. {
  22. _todo = new ToDoItem { Id = 1, Title = "title", Description = "desc" };
  23. return this;
  24. }
  25. public ToDoItem Build() => _todo;
  26. }
  27. ```
  28. ```
  29. public class ToDoItem : BaseEntity, IAggregateRoot
  30. {
  31. public string Title { get; set; } = string.Empty;
  32. public string Description { get; set; }
  33. public bool IsDone { get; private set; }
  34. ......
  35. }
  36. ```