- C#
古いDLLは"♥"とかのユニコード文字が使われているファイルにアクセスできないことがあります。
幸いなことにWindowsのファイルは8.3形式の別名のファイル名(ショートファイル名)を持っており、その名前でアクセスすればうまくいく可能性があります。
サンプルコードは以下のようになります。.Net にはショートファイル名を取得する機能がないので、Win32APIを使用して取得します。
NeeViewではこの方法でSusieプラグインでのユニコードファイル名アクセスを実現しています。
> Console.WriteLine("Hello!")
Hello!
Straemのようなtypoを
Streamになおしてくれる、といった感じです。
if (action != null) action();といったコードを
action?.Invoke();のようなnull条件演算子を使用した修正を提案するようになりました。
set MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" set SOLUTION="C:\Documents\Visual Studio 2015\Projects\MyProject\MyProject.sln" %MSBUILD% %SOLUTION% /p:Configuration=Release /t:Clean,BuildMSBuild.exe のパスに気をつけてください。
// サンプル
using (var process = new System.Diagnostics.Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true; // 標準出力リダイレクトON
process.StartInfo.StandardOutputEncoding = Encoding.UTF8; // エンコーディング設定
process.StartInfo.FileName = ... ;
process.StartInfo.Arguments = ... ;
process.Start();
process.WaitForExit();
string text = process.StandardOutput.ReadToEnd(); // 標準出力を得る
:
}
【MSDN】% 演算子 (C# リファレンス)
http://msdn.microsoft.com/ja-jp/library/0w4e0fzs.aspx
float NormalizeLoopRange(float val, float min, float max)
{
if (min >= max) throw new System.ArgumentException("need min < max");
if (val >= max)
{
return min + (val - min) % (max - min);
}
else if (val < min)
{
return max - (min - val) % (max - min);
}
else
{
return val;
}
}
あまり動作検証していませんのでバグがあったらすみません。
// Button1 Click Event
private async void Button1_Click(object sender, RoutedEventArgs e)
{
this.Button1.IsEnabled = false;
try
{
for (int i = 0; i < 10; i++)
{
this.TextBox1.AppendText(i + "\n");
#if true
// 非同期になるし、例外キャッチできる
await Task.Run(async () => HeavyProcess(i));
// コンパイラ警告が気になる場合は適当なawaitを追加
//await Task.Run(async () => {HeavyProcess(i); await Task.Yield();});
#else
// 非同期になるが、例外キャッチできない
await Task.Run(() => HeavyProcess(i));
#endif
}
}
catch (Exception ex)
{
this.TextBox1.AppendText(ex.Message);
}
this.Button1.IsEnabled = true;
}
// Heavy Process
void HeavyProcess(int count)
{
System.Threading.Thread.Sleep(1000);
if (count >= 5) throw new ApplicationException("例外発生!!");
}