Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

.NET

Determine whether you are behind a proxy or not with .NET

You can get the default proxy setting for a specific url with System.Net.WebRequest.GetSystemWebProxy().GetProxy(). The result is System.Uri object, and its OriginalString property will be the same the parameter if you are not behind a pro…

AltCoverでVB.NETのコードカバレッジが取れるか?

結論 OpenCoverがアーカイブモードに入ってしまった。後継として推されていたAltCoverでも、OpenCoverと同じように行単位のC1が取れそう。 手順 QuickStart Guideに記載の通り、テストケースの格納されているプロジェクト中でdotnet add package AltCoverす…

OpenCoverでVB.NETのコードカバレッジが取れるか?

結論 OpenCover VB.NETとかでググってもぜんぜん事例が出てこないので心配になるが、OpenCoverでVB.NETのコードカバレッジも取れる。ちゃんと行単位でのC1 coverage(branch coverage, 分岐網羅)も取れる。Coverletと違って、C1が100%実行されていないのに1…

CoverletでVB.NETのコードカバレッジが取れるか?

結論 https://docs.microsoft.com/ja-jp/dotnet/core/testing/unit-testing-code-coverage では「Coverlet とは、C# 用のクロスプラットフォームのコード カバレッジ フレームワーク」と言っているが、実際にはCoverletでVB.NETのコードカバレッジも取れる。…

How to change locale of error messages of PowerShell interpreter

Problem You can set locale of the current thread in PowerShell like below: [System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]("en-US") But error messages of PowerShell interpreter shows in current …

How to use additional character encodings in PowerShell Core (Linux) and Desktop (Windows)

Problem You have to call [System.Text.Encoding]::RegisterProvider([System.Text.CodePagesEncodingProvider]::Instance) when you want to use additional character encodings in PowerShell Core (Linux). On the other hand, calling [System.Text.En…

XmlNode.SelectNodes() always returns List in PowerShell 2.0

Problem: In PowerShell, by using XML DOM API in .NET, you can access to a child element in XML as a ordinary property. PS > $xml = New-Object System.Xml.XmlDocument PS > $xml.LoadXml('<a><b id="1">foo</b></a>') PS > $xml.SelectNodes('//a').b id #text -- ----- …

.NET cannot distinguish Shift_JIS from MS932(Windows-31J)

Context: Japanese character encoding Shift_JIS (シフトJIS) and Microsoft Codepage 932 (a.k.a. MS932, Windows-31J in IANA) are slightly different. For example, full-width cent sign (¢) is 0x8191 in both Shift_JIS and MS932, but it is mappe…

Trimmed characters by trim() are different between languages

String object in .NET (PowerShell), JavaScript, and Java all have trim() method. But trimmed characters by trim() are different between these languages. # codepoint .NET JavaScript Java 1 0000-0008 ✘ ✘ ✔ 2 0009-000D ✔ ✔ ✔ 3 000E-001F ✘ ✘ ✔…