Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

C#: count Environment.ProcessId, ProcessorCount, OSVersion and AppContext.BaseDirectory as environment reads (#1449) (#1492)

Hashem Alkhanaizi83d1fd3fe5d1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f18ea469..21c5a6ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- C#: `Environment.ProcessId`, `Environment.ProcessorCount`, `Environment.OSVersion`,
+ `Environment.UserDomainName`, `Environment.GetCommandLineArgs` and `AppContext.BaseDirectory`
+ count as reading the environment, as `Environment.CurrentDirectory` does, so `bridge` keeps a
+ method that reads one in C# and `analyze` lists it under "State outside the arguments" (#1449).
- `docs/STATUS.md` and its Tamil copy no longer list a CLI front door under Python's `package`
cell: `package` lays out npm packages only for the front door of a Node CLI (run as
`node node_modules/<package>/<file>`) and refuses any other, such as `python3 tool.py`. The test
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index 3ae21e9a..2a093136 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -225,6 +225,12 @@ fn environment(lang: Lang) -> &'static [&'static str] {
"Environment.GetFolderPath",
"Directory.GetCurrentDirectory(",
"Path.GetTempPath(",
+ "Environment.ProcessId",
+ "Environment.ProcessorCount",
+ "Environment.OSVersion",
+ "Environment.UserDomainName",
+ "Environment.GetCommandLineArgs",
+ "AppContext.BaseDirectory",
],
Lang::Powershell => &["$env:", "[environment]::", "get-location", "$pwd", "$home"],
Lang::Swift => &[
@@ -1742,6 +1748,14 @@ mod tests {
Lang::Java,
"String f(String x){ return System.getenv(\"HOME\") + x; }",
),
+ (
+ Lang::Csharp,
+ "public static int F(int x) => Environment.ProcessorCount * x;",
+ ),
+ (
+ Lang::Csharp,
+ "public static string F(string x) => Path.Combine(AppContext.BaseDirectory, x);",
+ ),
(Lang::Ruby, "def self.f(x)\n ENV.fetch('HOME') + x\nend"),
(Lang::Ruby, "def self.f(x)\n File.join(Dir.tmpdir, x)\nend"),
(Lang::Ruby, "def self.f(x)\n Socket.gethostname + x\nend"),