1
讓我們假設我有一些對象使用的「輔助」方法。擴展與部分
private int MatchRegex(string regex, string input)
{
var match = Regex.Match(input, regex);
return match.Success ? Convert.ToInt32(match.Groups[1].Value) : 0;
}
private string Exec(string arguments, string path = "", bool oneLine = false)
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
if (path != "")
p.StartInfo.WorkingDirectory = path;
p.StartInfo.FileName = "binary.exe";
p.StartInfo.Arguments = arguments;
p.Start();
string output = oneLine ? p.StandardOutput.ReadLine() : p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
你會選擇移出它們:另一個類,部分類或擴展方法?爲什麼?
同意你對'Exec'的回答,但是根本無法得到你對靜態'Regex.Match'和'MatchRegex'方法的意義。 – zerkms 2010-08-22 09:30:13
明白了,很好的答案。似乎是最佳的。 – zerkms 2010-08-22 09:36:02