这是半个问题和半个有趣的测验,因为正则表达式会是可笑地复杂并难以创建。如果我自己做(,因为我实际上需要使用它),我会写一个文件解析器而不是正则表达式,尽管我知道在这种情况下可以使用正则表达式,并且我认为也许是一些喜欢挑战的StackOverflow编码人员。这个替换正确的正则表达式是什么?
作为“奖励”,我会将问题保留7天,此时150声誉的赏金将归于具有正确答案的人。我知道回答者的声誉可能大于3K,但代表声望仍然很高。 :)
正则表达式将不得不转向:
[DllImport(EngineDll)]
public static extern int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth));
分为:
public static int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth))
{
if (Engine.ThreadSafe)
{
lock (typeof(Dll))
{
return Dll.Graphics(width, height, depth, hertz, flags);
}
}
else
{
return Dll.Graphics(width, height, depth, hertz, flags);
}
}
由于多完全不需要,你可以拥有这一切在1号线,如果你发现它更容易解析:
public static int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth)) { if (Engine.ThreadSafe) { lock (typeof(Dll)) { return Dll.Graphics(width, height, depth, hertz, flags); } } else { return Dll.Graphics(width, height, depth, hertz, flags); } }
现在,如果它不够明显,什么变量是返回类型,方法名称,参数类型,参数名称,参数是否具有默认值,在这种情况下是缺省值。该函数可能是一个void,在这种情况下,不应该有return语句。
根据要求:第二输入 - 输出:
[DllImport(EngineDll)]
public static extern void EndRender();
输出:
public static void EndRender()
{
if (Engine.ThreadSafe)
{
lock (typeof(Dll))
{
Dll.EndRender();
}
}
else
{
Dll.EndRender();
}
}
再次,1-衬垫接受。
祝你好运! :)
请注意所有可能会说我只是懒惰的人:改变问题。
我添加了`fun`和`code-bowling`标签,因为如你所说这是一项挑战,并不是真正适合这项工作的工具。但它看起来有趣......哦,为了清楚起见,你想要取代什么?转型的规则是什么?你只是期望参数名称添加到回调? – ircmaxell 2011-01-20 03:24:33
@ircmaxell:我不明白你的问题,对不起。谨慎阐述? – Lazlo 2011-01-20 03:28:16
所以你想要的基础知识是从源移动到目的地的类名,输入参数列表已移动,并且附加到两个返回的参数名称正确? – ircmaxell 2011-01-20 03:30:15