Added new Property CalledFrom which will return the first local in the stack

This commit is contained in:
Rich 2010-01-08 14:34:16 +00:00
parent 9180fba5ec
commit c7294d5ffd

View File

@ -104,6 +104,31 @@ namespace Volian.Controls.Library
return sb.ToString();
return "No Local Method";
}
public static string CalledFrom
{
get
{
StackTrace st = new StackTrace(true);
StackFrame[] sfs = st.GetFrames();
int count = 0;
foreach (StackFrame sf in sfs)
{
if (sf.GetFileLineNumber() != 0)
{
count++;
{
string sMethod = sf.GetMethod().Name;
string sNamespace = sf.GetMethod().ReflectedType.Namespace;
string sType = sf.GetMethod().ReflectedType.Name;
sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber());
if (count > 3)
return string.Format("{0}.{1}.{2}", sNamespace, sType, sMethod);
}
}
}
return "No Local Method";
}
}
private static StackFrame[] _LastSFS;
private static int MatchingStackFrame(StackFrame[] sfs)
{