修訂 | cfa22461ae837e893170d945e08595c56e7c4bf7 (tree) |
---|---|
時間 | 2022-05-21 18:58:48 |
作者 | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[MOD] キャプションクラスをアプリ側で拡張可能なようにリファクタ
@@ -11,8 +11,8 @@ namespace CleanAuLait48.Core.Resource | ||
11 | 11 | public const string MSG_KEY_CAPTION_ERROR = "Caption.Error"; |
12 | 12 | public const string MSG_KEY_CAPTION_EXCEPTION = "Caption.Exception"; |
13 | 13 | |
14 | - private readonly IMessageRepository repo; | |
15 | - private readonly DlgInfo defaultDlgInfo; | |
14 | + protected readonly IMessageRepository repo; | |
15 | + protected readonly DlgInfo defaultDlgInfo; | |
16 | 16 | |
17 | 17 | public CaptionFormatter(IMessageRepository repo) |
18 | 18 | { |
@@ -32,44 +32,32 @@ namespace CleanAuLait48.Core.Resource | ||
32 | 32 | |
33 | 33 | public string GetInfoCaption() |
34 | 34 | { |
35 | - return GetInfoCaption(null); | |
35 | + return GetCaption(MSG_KEY_CAPTION_INFO); | |
36 | 36 | } |
37 | 37 | |
38 | 38 | public string GetInfoCaption(DlgInfo dlgInfo) |
39 | 39 | { |
40 | - if (dlgInfo == null) | |
41 | - { | |
42 | - dlgInfo = defaultDlgInfo; | |
43 | - } | |
44 | - return string.Format(repo.Get(MSG_KEY_CAPTION_INFO), dlgInfo.Caption); | |
40 | + return GetCaption(MSG_KEY_CAPTION_INFO, dlgInfo); | |
45 | 41 | } |
46 | 42 | |
47 | 43 | public string GetWarnCaption() |
48 | 44 | { |
49 | - return GetWarnCaption(null); | |
45 | + return GetCaption(MSG_KEY_CAPTION_WARN); | |
50 | 46 | } |
51 | 47 | |
52 | 48 | public string GetWarnCaption(DlgInfo dlgInfo) |
53 | 49 | { |
54 | - if (dlgInfo == null) | |
55 | - { | |
56 | - dlgInfo = defaultDlgInfo; | |
57 | - } | |
58 | - return string.Format(repo.Get(MSG_KEY_CAPTION_WARN), dlgInfo.Caption); | |
50 | + return GetCaption(MSG_KEY_CAPTION_WARN, dlgInfo); | |
59 | 51 | } |
60 | 52 | |
61 | 53 | public string GetErrorCaption() |
62 | 54 | { |
63 | - return GetErrorCaption(null); | |
55 | + return GetCaption(MSG_KEY_CAPTION_ERROR); | |
64 | 56 | } |
65 | 57 | |
66 | 58 | public string GetErrorCaption(DlgInfo dlgInfo) |
67 | 59 | { |
68 | - if (dlgInfo == null) | |
69 | - { | |
70 | - dlgInfo = defaultDlgInfo; | |
71 | - } | |
72 | - return string.Format(repo.Get(MSG_KEY_CAPTION_ERROR), dlgInfo.Caption); | |
60 | + return GetCaption(MSG_KEY_CAPTION_ERROR, dlgInfo); | |
73 | 61 | } |
74 | 62 | |
75 | 63 | public string GetExceptionCaption(Exception e) |
@@ -85,5 +73,20 @@ namespace CleanAuLait48.Core.Resource | ||
85 | 73 | } |
86 | 74 | return string.Format(repo.Get(MSG_KEY_CAPTION_EXCEPTION), dlgInfo.Caption, e.GetType().Name); |
87 | 75 | } |
76 | + | |
77 | + protected string GetCaption(string msgCaptionKey) | |
78 | + { | |
79 | + return GetCaption(msgCaptionKey, null); | |
80 | + } | |
81 | + | |
82 | + protected string GetCaption(string msgCaptionKey, DlgInfo dlgInfo) | |
83 | + { | |
84 | + if (dlgInfo == null) | |
85 | + { | |
86 | + dlgInfo = defaultDlgInfo; | |
87 | + } | |
88 | + return string.Format(repo.Get(msgCaptionKey), dlgInfo.Caption); | |
89 | + } | |
90 | + | |
88 | 91 | } |
89 | 92 | } |