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