修订版 | c3a256ccb4a9a5823695d2237d31680b12931560 (tree) |
---|---|
时间 | 2022-11-29 23:54:33 |
作者 | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[MOD] キャプション書式化機能でキャプションの取得と書式化を行う機能の区別を明確にした
@@ -3,10 +3,14 @@ | ||
3 | 3 | public class CaptionFormatter : ICaptionFormatter |
4 | 4 | { |
5 | 5 | public const string MSG_KEY_CAPTION = "Caption"; |
6 | - public const string MSG_KEY_CAPTION_INFO = "Caption.Info"; | |
7 | - public const string MSG_KEY_CAPTION_WARN = "Caption.Warn"; | |
8 | - public const string MSG_KEY_CAPTION_ERROR = "Caption.Error"; | |
9 | - public const string MSG_KEY_CAPTION_EXCEPTION = "Caption.Exception"; | |
6 | + | |
7 | + public const string MSG_KEY_PREFIX_CAPTION_FORMAT = "Caption.Format."; | |
8 | + | |
9 | + public const string MSG_KEY_CAPTION_FORMAT_INFO = MSG_KEY_PREFIX_CAPTION_FORMAT + "Info"; | |
10 | + public const string MSG_KEY_CAPTION_FORMAT_WARN = MSG_KEY_PREFIX_CAPTION_FORMAT + "Warn"; | |
11 | + public const string MSG_KEY_CAPTION_FORMAT_ERROR = MSG_KEY_PREFIX_CAPTION_FORMAT + "Error"; | |
12 | + public const string MSG_KEY_CAPTION_FORMAT_CONFIRM = MSG_KEY_PREFIX_CAPTION_FORMAT + "Confirm"; | |
13 | + public const string MSG_KEY_CAPTION_FORMAT_EXCEPTION = MSG_KEY_PREFIX_CAPTION_FORMAT + "Exception"; | |
10 | 14 | |
11 | 15 | protected readonly IMessageRepository repo; |
12 | 16 |
@@ -15,67 +19,100 @@ | ||
15 | 19 | this.repo = repo; |
16 | 20 | } |
17 | 21 | |
18 | - public string GetCaption() | |
22 | + public string GetDefaultCaption() | |
23 | + { | |
24 | + return GetCaption(MSG_KEY_CAPTION); | |
25 | + } | |
26 | + | |
27 | + public string GetCaption(string captionKey) | |
19 | 28 | { |
20 | - return repo.Get(MSG_KEY_CAPTION); | |
29 | + return this.repo.Get(captionKey); | |
21 | 30 | } |
22 | 31 | |
23 | 32 | public string GetInfoCaption() |
24 | 33 | { |
25 | - return GetCaption(MSG_KEY_CAPTION_INFO); | |
34 | + return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_INFO); | |
26 | 35 | } |
27 | 36 | |
28 | - public string GetInfoCaption(string caption) | |
37 | + public string FormatInfoCaption(string captionKey) | |
29 | 38 | { |
30 | - return GetCaption(MSG_KEY_CAPTION_INFO, caption); | |
39 | + return FormatCaption(MSG_KEY_CAPTION_FORMAT_INFO, captionKey); | |
31 | 40 | } |
32 | 41 | |
33 | 42 | public string GetWarnCaption() |
34 | 43 | { |
35 | - return GetCaption(MSG_KEY_CAPTION_WARN); | |
44 | + return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_WARN); | |
36 | 45 | } |
37 | 46 | |
38 | - public string GetWarnCaption(string caption) | |
47 | + public string FormatWarnCaption(string captionKey) | |
39 | 48 | { |
40 | - return GetCaption(MSG_KEY_CAPTION_WARN, caption); | |
49 | + return FormatCaption(MSG_KEY_CAPTION_FORMAT_WARN, captionKey); | |
41 | 50 | } |
42 | 51 | |
43 | 52 | public string GetErrorCaption() |
44 | 53 | { |
45 | - return GetCaption(MSG_KEY_CAPTION_ERROR); | |
54 | + return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR); | |
55 | + } | |
56 | + | |
57 | + public string FormatErrorCaption(string captionKey) | |
58 | + { | |
59 | + return FormatCaption(MSG_KEY_CAPTION_FORMAT_ERROR, captionKey); | |
60 | + } | |
61 | + | |
62 | + public string GetConfirmCaption() | |
63 | + { | |
64 | + return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR); | |
46 | 65 | } |
47 | 66 | |
48 | - public string GetErrorCaption(string caption) | |
67 | + public string FormatConfirmCaption(string captionKey) | |
49 | 68 | { |
50 | - return GetCaption(MSG_KEY_CAPTION_ERROR, caption); | |
69 | + return FormatCaption(MSG_KEY_CAPTION_FORMAT_CONFIRM, captionKey); | |
51 | 70 | } |
52 | 71 | |
53 | 72 | public string GetExceptionCaption(Exception e) |
54 | 73 | { |
55 | - return GetExceptionCaption(e, null); | |
74 | + return FormatExceptionCaption(e, null); | |
56 | 75 | } |
57 | 76 | |
58 | - public string GetExceptionCaption(Exception e, string caption) | |
77 | + public string FormatExceptionCaption(Exception e, string captionKey) | |
59 | 78 | { |
60 | - if (string.IsNullOrEmpty(caption)) | |
79 | + string caption; | |
80 | + | |
81 | + if (string.IsNullOrEmpty(captionKey)) | |
82 | + { | |
83 | + caption = GetDefaultCaption(); | |
84 | + } | |
85 | + else | |
61 | 86 | { |
62 | - caption = GetCaption(); | |
87 | + caption = GetCaption(captionKey); | |
63 | 88 | } |
64 | - return string.Format(repo.Get(MSG_KEY_CAPTION_EXCEPTION), caption, e.GetType().Name); | |
89 | + | |
90 | + string format = GetCaption(MSG_KEY_CAPTION_FORMAT_EXCEPTION); | |
91 | + | |
92 | + return string.Format(format, caption, e.GetType().Name); | |
65 | 93 | } |
66 | 94 | |
67 | - protected string GetCaption(string msgCaptionKey) | |
95 | + protected string FormatDefaultCaption(string captionFormatKey) | |
68 | 96 | { |
69 | - return GetCaption(msgCaptionKey, null); | |
97 | + return FormatCaption(captionFormatKey, null); | |
70 | 98 | } |
71 | 99 | |
72 | - protected string GetCaption(string msgCaptionKey, string caption) | |
100 | + protected string FormatCaption(string captionFormatKey, string captionKey) | |
73 | 101 | { |
74 | - if (string.IsNullOrEmpty(caption)) | |
102 | + string caption; | |
103 | + | |
104 | + if (string.IsNullOrEmpty(captionKey)) | |
105 | + { | |
106 | + caption = GetDefaultCaption(); | |
107 | + } | |
108 | + else | |
75 | 109 | { |
76 | - caption = GetCaption(); | |
110 | + caption = GetCaption(captionKey); | |
77 | 111 | } |
78 | - return string.Format(repo.Get(msgCaptionKey), caption); | |
112 | + | |
113 | + string format = GetCaption(captionFormatKey); | |
114 | + | |
115 | + return string.Format(format, caption); | |
79 | 116 | } |
80 | 117 | |
81 | 118 | } |
@@ -2,14 +2,17 @@ | ||
2 | 2 | { |
3 | 3 | public interface ICaptionFormatter |
4 | 4 | { |
5 | - string GetCaption(); | |
6 | - string GetErrorCaption(); | |
7 | - string GetErrorCaption(string caption); | |
8 | - string GetExceptionCaption(Exception e); | |
9 | - string GetExceptionCaption(Exception e, string caption); | |
5 | + string GetDefaultCaption(); | |
6 | + string GetCaption(string captionKey); | |
10 | 7 | string GetInfoCaption(); |
11 | - string GetInfoCaption(string caption); | |
8 | + string FormatInfoCaption(string captionKey); | |
12 | 9 | string GetWarnCaption(); |
13 | - string GetWarnCaption(string caption); | |
10 | + string FormatWarnCaption(string captionKey); | |
11 | + string GetErrorCaption(); | |
12 | + string FormatErrorCaption(string captionKey); | |
13 | + string GetConfirmCaption(); | |
14 | + string FormatConfirmCaption(string captionKey); | |
15 | + string GetExceptionCaption(Exception e); | |
16 | + string FormatExceptionCaption(Exception e, string captionKey); | |
14 | 17 | } |
15 | 18 | } |
\ No newline at end of file |