Parcourir la source

强类型枚举

master
qdjjx il y a 3 ans
Parent
révision
dfb7f9ba24

+ 1
- 1
专题/后端/DDD/5、Result模式,一站式解决响应问题.md Voir le fichier

@@ -174,7 +174,7 @@ public async Task<Result<BlogCategory>> UpdateAsync(BlogCategory blogCategory)
174 174
 如何影射`Result`结果呢?
175 175
 
176 176
 ```
177
-   public class TranslateResultToActionResultAttribute : ActionFilterAttribute
177
+   public class  ultAttribute : ActionFilterAttribute
178 178
     {
179 179
         public override void OnActionExecuted(ActionExecutedContext context)
180 180
         {

+ 130
- 0
专题/后端/DDD/6、强类型枚举.md Voir le fichier

@@ -0,0 +1,130 @@
1
+```
2
+<PackageReference Include="Ardalis.SmartEnum" Version="2.0.0" />
3
+```
4
+
5
+
6
+
7
+```
8
+    /// <summary>
9
+    /// 枚举作为状态机
10
+    /// </summary>
11
+    public abstract class ReservationStatus : SmartEnum<ReservationStatus>
12
+    {
13
+        private ReservationStatus(string name, int value) : base(name, value) { }
14
+
15
+        public abstract bool CanTransitionTo(ReservationStatus next);
16
+
17
+        public static readonly ReservationStatus New = new NewStatus();
18
+        public static readonly ReservationStatus Accepted = new AcceptedStatus();
19
+        public static readonly ReservationStatus Paid = new PaidStatus();
20
+        public static readonly ReservationStatus Cancelled = new CancelledStatus();
21
+
22
+        private sealed class NewStatus : ReservationStatus
23
+        {
24
+            public NewStatus() : base("New", 0)
25
+            {
26
+            }
27
+
28
+            public override bool CanTransitionTo(ReservationStatus next) =>
29
+                next == ReservationStatus.Accepted || next == ReservationStatus.Cancelled;
30
+        }
31
+
32
+        private sealed class AcceptedStatus : ReservationStatus
33
+        {
34
+            public AcceptedStatus() : base("Accepted", 1)
35
+            {
36
+            }
37
+
38
+            public override bool CanTransitionTo(ReservationStatus next) =>
39
+                next == ReservationStatus.Paid || next == ReservationStatus.Cancelled;
40
+        }
41
+
42
+        private sealed class PaidStatus : ReservationStatus
43
+        {
44
+            public PaidStatus() : base("Paid", 2)
45
+            {
46
+            }
47
+
48
+            public override bool CanTransitionTo(ReservationStatus next) =>
49
+                next == ReservationStatus.Cancelled;
50
+        }
51
+
52
+        private sealed class CancelledStatus : ReservationStatus
53
+        {
54
+            public CancelledStatus() : base("Cancelled", 3)
55
+            {
56
+            }
57
+
58
+            public override bool CanTransitionTo(ReservationStatus next) =>
59
+                false;
60
+        }
61
+
62
+
63
+    }
64
+
65
+    /// <summary>
66
+    /// 枚举可以初始化
67
+    /// </summary>
68
+    public sealed class TestEnum : SmartEnum<TestEnum>
69
+    {
70
+       private TestEnum(string name, int value) : base(name, value)
71
+        {
72
+
73
+        }
74
+
75
+        public static readonly TestEnum One = new TestEnum(nameof(One), 1);
76
+        public static readonly TestEnum Two = new TestEnum(nameof(Two), 2);
77
+        public static readonly TestEnum Three = new TestEnum(nameof(Three), 3);
78
+    }
79
+
80
+    /// <summary>
81
+    /// 别名
82
+    /// </summary>
83
+    public sealed class TestEnum1 : SmartEnum<TestEnum1>
84
+    {
85
+        //真实的值通过构造函数来设定
86
+        private TestEnum1(string name, ushort value) : base(name, value) { }
87
+
88
+        /// <summary>
89
+        /// One看作是别名
90
+        /// </summary>
91
+        public static readonly TestEnum1 One = new TestEnum1("a", 1);
92
+        public static readonly TestEnum1 Two = new TestEnum1("b", 2);
93
+        public static readonly TestEnum1 Three = new TestEnum1("a", 3);
94
+    }
95
+
96
+    /// <summary>
97
+    /// 枚举也可以被继承
98
+    /// 也可以是抽象
99
+    /// </summary>
100
+    public abstract class EmployeeType : SmartEnum<EmployeeType>
101
+    {
102
+        private EmployeeType(string name, int value):base(name, value) { }
103
+        public abstract decimal BonusSize { get; }
104
+
105
+        public static readonly EmployeeType Manager = new ManagerType();
106
+        public static readonly EmployeeType Assistant = new AssistantType();
107
+
108
+        
109
+        private sealed class ManagerType : EmployeeType
110
+        {
111
+            public ManagerType():base("Manager",1)
112
+            {
113
+
114
+            }
115
+
116
+            public override decimal BonusSize => 10m;
117
+        }
118
+
119
+        private sealed class AssistantType : EmployeeType
120
+        {
121
+            public AssistantType() : base("Assistant",2)
122
+            {
123
+
124
+            }
125
+
126
+            public override decimal BonusSize => 20m;
127
+        }
128
+    }
129
+```
130
+

+ 26
- 2
团队/解决一次git问题.md Voir le fichier

@@ -1,8 +1,32 @@
1
-出现非常混乱的情况,首先本地回滚到某个版本:
1
+> 出现非常混乱的情况,首先本地回滚到某个版本:
2 2
 ```
3 3
 git reset xxx --hard
4 4
 ```
5 5
 然后让远程也回滚
6 6
 ```
7 7
 git push origin master -f
8
-```
8
+```
9
+
10
+> 查看最近记录
11
+
12
+```
13
+git log --since=1.days
14
+git log --since=1.weeks
15
+git log -p -2 --oneline
16
+```
17
+
18
+> Please commit your changes or stash them before you merge. 场景是不想把本地的一个修改文件提交上去
19
+
20
+```
21
+git stash
22
+git pull 
23
+git stash pop
24
+
25
+另外:
26
+git stash list
27
+git stash clear
28
+```
29
+
30
+> 删除缓存区的内容
31
+
32
+正确的做法应该是:git rm --cached logs/xx.log,然后更新 .gitignore 忽略掉目标文件,最后 git commit -m "We really don't want Git to track this anymore!"

Chargement…
Annuler
Enregistrer