我如何从功能中获取身体
Func<bool> methodCall = () => output.SendToFile();
if (methodCall())
Console.WriteLine("Success!");
Run Code Online (Sandbox Code Playgroud)
我需要将此"output.SendToFile()"作为字符串
另一个例子
string log = "";
public void Foo<T>(Func<T> func)
{
try
{
var t = func();
}
catch (Exception)
{
//here I need to add the body of the lambda
// log += func.body;
}
}
public void Test()
{
var a = 5;
var b = 6;
Foo(() => a > b);
}
Run Code Online (Sandbox Code Playgroud) 我在远程会话下使用Invoke-Expression并且在抛出异常时 - 它只返回RemoteException而没有任何堆栈跟踪信息.例:
try
{
Invoke-Expression "$command 2>&1"
}
catch
{
Write-Host $_
}
Run Code Online (Sandbox Code Playgroud)
如果我将重定向错误排除到output(2>&1) - 我得到了正确的错误,但它调用了不需要的调试控制台(来自$ command),这是使用重定向隐藏的.
Start-Process -NoNewWindow -FilePath $CmdExe -ArgumentList $Arguments
Run Code Online (Sandbox Code Playgroud)
使用Start-Process我可以看到完整的堆栈跟踪,但也有不需要的调试控制台.
如何从远程会话下的抛出异常中获取完整的堆栈跟踪和正确的异常?谢谢.
需要从"1.2.3.4"到"1.2"的字符串中获取子字符串我有这个解决方案:
string version = "1.2.3.4";
var major = version.Substring(0, version.Substring(0, version.LastIndexOf('.')).LastIndexOf('.'));
Run Code Online (Sandbox Code Playgroud)
但它看起来很难看.什么是最好的方法呢?(注意)初始字符串可能具有不同的大小,如11.22.33.44或其他