本文整理汇总了C#中System.Diagnostics.StackFrame.GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# StackFrame.GetMethod方法的具体用法?C# StackFrame.GetMethod怎么用?C# StackFrame.GetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackFrame
的用法示例。
在下文中一共展示了StackFrame.GetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PromoteException
//Can only be called inside a service
public static void PromoteException(Exception error,MessageVersion version,ref Message fault)
{
StackFrame frame = new StackFrame(1);
Type serviceType = frame.GetMethod().ReflectedType;
PromoteException(serviceType,error,version,ref fault);
}
示例2: Find
/// <summary>
/// 指定されたクラスのStackFrameを取得する。
/// </summary>
/// <returns>StackFrame</returns>
public static List<StackFrame> Find(Type type)
{
List<StackFrame> list = new List<StackFrame>();
string className = type.FullName;
for (int i = 0; i < MAX; i++)
{
StackFrame stackFrame = new StackFrame(i, true);
if (stackFrame.GetMethod() == null)
{
break;
}
string stackFrameClassName = stackFrame.GetMethod().ReflectedType.FullName;
if (stackFrameClassName.Equals(className))
{
list.Add(stackFrame);
}
else if(list.Count > 0)
{
break;
}
}
if (list.Count == 0)
{
throw new InvalidOperationException("cannot find a StackFrame of " + type.FullName);
}
return list;
}
示例3: Registrar
public static void Registrar(string mensagem)
{
var fullName = "";
var stackFrame = new StackFrame(1);
Type declaringType = stackFrame.GetMethod().DeclaringType;
if (declaringType != null)
{
fullName += declaringType.FullName;
}
fullName += "." + stackFrame.GetMethod().Name + "()";
var log = new StringBuilder();
log.AppendLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
log.AppendLine(DateTime.Now.ToString("dd/MM/yyyy - HH:mm:ss"));
log.AppendLine(fullName);
log.AppendLine(mensagem);
log.AppendLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
string dir = ConfigurationManager.AppSettings["logPath"];
string fileName = string.Format("log_" + DateTime.Now.Year + "_" + DateTime.Now.Month.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0') + ".avlog");
string path = Path.Combine(dir, fileName);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
var writer = new StreamWriter(path, true);
writer.Write(log);
writer.Close();
}
示例4: AppendCall
internal void AppendCall(int index)
{
SecurityCallFrame call = new SecurityCallFrame();
m_StackFrames.Add(call);
StackFrame frame = new StackFrame(index);
call.CallerType = frame.GetMethod().DeclaringType.ToString();
call.Operation = frame.GetMethod().Name + "()";
if(Count == 1)
{
call.Address = Environment.MachineName;
call.Authentication = Thread.CurrentPrincipal.Identity.AuthenticationType;
call.ActivityId = Guid.NewGuid();
call.IdentityName = Thread.CurrentPrincipal.Identity.Name;
if(call.IdentityName == String.Empty)
{
call.IdentityName =WindowsIdentity.GetCurrent().Name;
}
call.Operation = frame.GetMethod().Name + "()";
}
else //Must be in a service already
{
//Add local information for this service
call.Address = OperationContext.Current.Channel.LocalAddress.Uri.ToString();
call.Authentication = ServiceSecurityContext.Current.PrimaryIdentity.AuthenticationType;
call.IdentityName = Thread.CurrentPrincipal.Identity.Name;
call.ActivityId = m_StackFrames[Count-2].ActivityId;
}
}
示例5: Main
public static int Main () {
MethodBase myMethodBase = MethodBase.GetCurrentMethod ();
MethodBase inlinedMethodBase = InlinedMethods.GetCurrentMethod ();
Assembly myExecutingAssembly = Assembly.GetExecutingAssembly ();
Assembly inlinedExecutingAssembly = InlinedMethods.GetExecutingAssembly ();
Assembly myCallingAssembly = Assembly.GetCallingAssembly ();
Assembly inlinedCallingAssembly = InlinedMethods.CallCallingAssembly ();
StackFrame myStackFrame = new StackFrame ();
StackFrame inlinedStackFrame = InlinedMethods.GetStackFrame ();
string myConstructorCalledFrom = new CallingAssemblyDependant ().CalledFrom;
string inlinedConstructorCalledFrom = CallingAssemblyDependant.CalledFromLibrary ();
StaticFlag.Flag = true;
bool strictFlag = ResourceStrictFieldInit.Single.Flag;
bool relaxedFlag = ResourceRelaxedFieldInit.Single.Flag;
Console.WriteLine ("[{0}]CurrentMethod: my {1}, inlined {2}, equals {3}",
TestFailed (myMethodBase == inlinedMethodBase),
myMethodBase.Name, inlinedMethodBase.Name,
myMethodBase == inlinedMethodBase);
Console.WriteLine ("[{0}]ExecutingAssembly: my {1}, inlined {2}, equals {3}",
TestFailed (myExecutingAssembly == inlinedExecutingAssembly),
myExecutingAssembly.GetName ().Name, inlinedExecutingAssembly.GetName ().Name,
myExecutingAssembly == inlinedExecutingAssembly);
Console.WriteLine ("[{0}]CallingAssembly: my {1}, inlined {2}, equals {3}",
TestFailed (myCallingAssembly == inlinedCallingAssembly),
myCallingAssembly.GetName ().Name, inlinedCallingAssembly.GetName ().Name,
myCallingAssembly == inlinedCallingAssembly);
Console.WriteLine ("[{0}]StackFrame.GetMethod: my {1}, inlined {2}, equals {3}",
TestFailed (myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name),
myStackFrame.GetMethod ().Name, inlinedStackFrame.GetMethod ().Name,
myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name);
Console.WriteLine ("[{0}]ConstructorCalledFrom: my {1}, inlined {2}, equals {3}",
TestFailed (myConstructorCalledFrom == inlinedConstructorCalledFrom),
myConstructorCalledFrom, inlinedConstructorCalledFrom,
myConstructorCalledFrom == inlinedConstructorCalledFrom);
Console.WriteLine ("[{0}]strictFlag: {1}, relaxedFlag: {2}",
TestFailed ((strictFlag != relaxedFlag)),
strictFlag, relaxedFlag);
if ((myMethodBase != inlinedMethodBase) &&
(myExecutingAssembly != inlinedExecutingAssembly) &&
(myCallingAssembly != inlinedCallingAssembly) &&
(myStackFrame.GetMethod ().Name != inlinedStackFrame.GetMethod ().Name) &&
(myConstructorCalledFrom != inlinedConstructorCalledFrom) &&
(strictFlag == relaxedFlag)) {
return 0;
} else {
return 1;
}
}
示例6: DebugLog
/// <summary>Prints a formatted message to the debug console.</summary>
/// <param name="obj">The source object.</param>
/// <param name="args">Comma separated list of items to print.</param>
public static void DebugLog( this object obj, params object[] args)
{
string str = args.Aggregate<object, string>("", (string a, object b) => {return a + b.ToString(); });
StackFrame sf = new StackFrame(1);
string src = sf.GetMethod().DeclaringType.Name + "(" + sf.GetMethod().Name + ")";
Debug.Print(string.Format("{0}: {1}", src, str));
}
示例7: GetLogger
public ILogger GetLogger()
{
StackFrame frame = new StackFrame(1, false);
Type t = frame.GetMethod() == null ? GetType() : frame.GetMethod().DeclaringType;
return GetLogger(t);
}
示例8: current
// get current method name
public static string current()
{
System.Diagnostics.StackFrame stackframe =
new System.Diagnostics.StackFrame(1, true);
return stackframe.GetMethod().ReflectedType.Name
+ "."
+ stackframe.GetMethod().Name ;
}
示例9: GetCallerIdentity
/// <summary>
/// Get the caller identity from the stacktrace
/// </summary>
/// <param name="skipFrames">The level of stack frame to skip</param>
/// <returns>The caller function</returns>
private static string GetCallerIdentity(int skipFrames)
{
var frame = new StackFrame(skipFrames, true);
if (null != frame.GetMethod() && null != frame.GetMethod().DeclaringType)
{
return string.Format("{0}.{1}", frame.GetMethod().DeclaringType.Name, frame.GetMethod().Name);
}
return string.Empty;
}
示例10: LogMsg
public void LogMsg(string message, params object[] args)
{
StackFrame stackFrame = new StackFrame(1);
DateTime timestamp = DateTime.Now.ToUniversalTime();
string csvFormattedMessage = string.Format(message, args).Replace(@"""", @"""""");
LogBuilder.AppendFormat(@"""[{0}]"",""[{1}]"",""[{2}]"",""{3}""", timestamp.ToLongTimeString(), stackFrame.GetMethod().DeclaringType.ToString(), stackFrame.GetMethod().Name, csvFormattedMessage);
LogBuilder.AppendLine();
}
示例11: CreateErrorLog
public static void CreateErrorLog(string LogMsg)
{
// Dim frame As StackFrame = New StackFrame(1, True)
//Dim ClassName As String = frame.GetMethod.ReflectedType.Name
//Dim FunctionName As String = frame.GetMethod.Name
//Dim LineNo As Integer = frame.GetFileLineNumber
StackFrame frame = new StackFrame(1, true);
string ClassName = frame.GetMethod().ReflectedType.Name;
string FuntionName = frame.GetMethod().Name;
int LineNo = frame.GetFileLineNumber();
CreateErrorLog(LogMsg, ClassName + "." + FuntionName, GetLocalIPAddress());
}
示例12: FormatLocation
public static string FormatLocation(StackFrame frame)
{
StringBuilder location = new StringBuilder();
location.Append(frame.GetMethod().DeclaringType.ToString());
location.Append("=>");
location.Append(frame.GetMethod().ToString());
location.Append(" [");
location.Append(frame.GetILOffset());
location.Append(":");
location.Append(frame.GetNativeOffset());
location.Append("]");
return location.ToString();
}
示例13: Enrich
public void Enrich(LogEvent e, out string propertyName, out object propertyValue)
{
var frame = new StackFrame(4); //warning! this can change after refactoring
propertyName = "method";
MethodBase method = frame.GetMethod();
var sb = new StringBuilder();
sb.Append(method.DeclaringType.FullName);
sb.Append(".");
sb.Append(method.Name);
sb.Append("(");
bool isFirst = true;
foreach(ParameterInfo p in method.GetParameters())
{
if (!isFirst)
{
sb.Append(", ");
}
else
{
isFirst = false;
}
sb.Append(p.ParameterType.Name);
sb.Append(" ");
sb.Append(p.Name);
}
sb.Append(")");
propertyValue = sb.ToString();
}
示例14: ShouldSetMemberfilterForMethodInfoOfTypeMethod
public void ShouldSetMemberfilterForMethodInfoOfTypeMethod()
{
StoryRunnerFilter filter = null;
MemberInfo member = null;
Given(
() =>
{
var stack = new StackFrame(2); //
member = stack.GetMethod();
}
);
When(
() => { filter = StoryRunnerFilter.GetFilter(member); }
);
Then(
() =>
{
Assert.That(filter.MethodNameFiler.ToString(), Is.EqualTo("^ShouldSetMemberfilterForMethodInfoOfTypeMethod$"));
Assert.That(filter.ClassNameFilter.ToString(), Is.EqualTo("^" + typeof (StoryRunnerFilterSpecs).Name + "$"));
Assert.That(filter.NamespaceFilter.ToString(), Is.EqualTo("^" + typeof(StoryRunnerFilterSpecs).Namespace + "$"));
}
);
}
示例15: GetClassLogger
public static ScopeLogger GetClassLogger(ILogTape baseLogger = null, int framesToSkip = 1)
{
// extracted from: https://github.com/NLog
string loggerName;
Type declaringType;
do
{
StackFrame frame = new StackFrame(framesToSkip, false);
var method = frame.GetMethod();
declaringType = method.DeclaringType;
if (declaringType == null)
{
loggerName = method.Name;
break;
}
framesToSkip++;
loggerName = declaringType.FullName;
} while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));
if (baseLogger == null)
baseLogger = commonLogTape;
return new ScopeLogger(loggerName, baseLogger);
}