3.1中提到我定義了一些公共配置項,現在我來說一說配置項的用法: 1. 提供軟體標識符 1 public static class CfgIndentifiers 2 { 3 public static readonly string Identifier = 4 #if DEBUG 5 "DEBU ...
3.1中提到我定義了一些公共配置項,現在我來說一說配置項的用法:
1. 提供軟體標識符
1 public static class CfgIndentifiers 2 { 3 public static readonly string Identifier = 4 #if DEBUG 5 "DEBUG" 6 #elif AI_USER 7 string.Empty 8 #elif IDUU_USER 9 "IDUU" 10 #elif Business_USER 11 "SQL" 12 #elif RELEASE 13 "ADV" 14 #else 15 "UNKNOWN" 16 #endif 17 ; 18 }
項目編譯後,Identifier是一個靜態只讀變數。即可以在UI上顯示給用戶看,告知版本,也可以在訪問後端API時,當作header傳過去。
2. 提供運行邏輯 布爾參考
1 public static class Configurations 2 { 3 public static bool IsUserVersion => 4 #if !USER 5 false; 6 #else 7 true; 8 #endif 9 10 public static bool IsDevVersion => !IsUserVersion; 11 12 public static bool IsNotIDUU => 13 #if IDUU_USER 14 false; 15 #else 16 true; 17 #endif 18 19 public static bool IsDebug => 20 #if DEBUG 21 true; 22 #else 23 false; 24 #endif 25 }
上面的兩個類供其它所有項目引用(當然其它一些涉及具體業務,就不展示了)。