Commit 42bf238
authored
fix: Init method in Env.cs for better initialization (#906)
* Refactor Init method in Env.cs for better initialization
Reordered the Init method to check _initialized flag at the start,
ensuring early return if already initialized. Moved _env dictionary
initialization before the check to guarantee setup before any
operations. Removed _initialized flag setting and env.json reading
from the try block, simplifying the initialization logic.
* Ensure _initialized is set only after successful deserialization
Moved _initialized = true; to after JSON deserialization to ensure
it is only set if deserialization is successful. Added a catch block
for JsonException to handle parsing errors and output an error
message to the console.
* Refactor path handling and update StreamReader syntax
Refactored code for better readability and robustness:
- Declared `path` as a `string`.
- Ensured `path` ends with a directory separator.
- Updated `StreamReader` initialization to new C# syntax.
* Refactor file path construction for "env.json"
Simplified the process of constructing the file path for "env.json" by replacing manual checks and concatenation with `Path.Combine`. This change makes the code more concise and less error-prone by leveraging built-in functionality for path handling.1 parent 86fbe1b commit 42bf238
1 file changed
+8
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
26 | | - | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
0 commit comments