C# 如何在c中获取调用方法属性#
我目前正在为我的应用程序编写一个错误记录器,基本上我感兴趣的是,在处理异常时,我从日志类调用函数CreateLogEntry(…)。 想法是,我希望CreateLogEntry(…)知道它是从方法BadFunction(…)中调用的,并在日志过程中检索其参数 现在我已经做了一些家庭作业(我想还不够:S),我确信我的解决方案在于System.Reflection,并且已经找到了一些关于如何枚举类()中所有函数的示例。 但是否有可能获得创建该异常的函数的名称 Ex(我得到的):C# 如何在c中获取调用方法属性#,c#,reflection,exception-handling,C#,Reflection,Exception Handling,我目前正在为我的应用程序编写一个错误记录器,基本上我感兴趣的是,在处理异常时,我从日志类调用函数CreateLogEntry(…)。 想法是,我希望CreateLogEntry(…)知道它是从方法BadFunction(…)中调用的,并在日志过程中检索其参数 现在我已经做了一些家庭作业(我想还不够:S),我确信我的解决方案在于System.Reflection,并且已经找到了一些关于如何枚举类()中所有函数的示例。 但是否有可能获得创建该异常的函数的名称 Ex(我得到的): 公共字符串GetCu
公共字符串GetCurrentMode()
{
字符串currentMode=“”;
尝试
{
currentMode=_host.Mode.ToString();
}
捕获(例外情况除外)
{
Common.morpheeeexception me=新的Common.morpheeeexception();
me.MethodName=“GetCurrentMode”;
me.NameSpace=“MorpheeScript”;
me.ErrorNumber=0;
me.ErrorDescription=例如消息;
me.StackTrace=ex.StackTrace;
抛出新的FaultException(我);
}
返回电流模式;
}
我想要的是:
public string GetCurrentMode()
{
string currentMode = "";
try
{
currentMode = _host.Mode.ToString();
}
catch(Exception ex)
{
Common.MorpheeException me = new Common.MorpheeException(ex);
// Here me should know that it is called from GetCurrentMode() and
// retrieve the parameters if there are any
throw new FaultException<Common.MorpheeException>(me);
}
return currentMode;
}
公共字符串GetCurrentMode()
{
字符串currentMode=“”;
尝试
{
currentMode=_host.Mode.ToString();
}
捕获(例外情况除外)
{
Common.morpheeeexception me=新的Common.morpheeeexception(ex);
//这里我应该知道它是从GetCurrentMode()调用的,并且
//检索参数(如果有)
抛出新的FaultException(我);
}
返回电流模式;
}
非常感谢您在
morpheeeexception
constructior中提供的帮助,然后使用它
public string GetCurrentMode()
{
string currentMode = "";
try
{
currentMode = _host.Mode.ToString();
}
catch(Exception ex)
{
Common.MorpheeException me = new Common.MorpheeException(ex);
// Here me should know that it is called from GetCurrentMode() and
// retrieve the parameters if there are any
throw new FaultException<Common.MorpheeException>(me);
}
return currentMode;
}