当前位置: 首页>>代码示例>>C#>>正文


C# StackFrame.GetMethod方法代码示例

本文整理汇总了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);
        }
开发者ID:JMnITup,项目名称:SMEX,代码行数:8,代码来源:ErrorHandlerHelper.cs

示例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;
 }
开发者ID:kaakaa,项目名称:FixtureBook,代码行数:31,代码来源:StackFrameFinder.cs

示例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();
        }
开发者ID:alvtatiane,项目名称:WCFAcaoVendas,代码行数:34,代码来源:LogErro.cs

示例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;
         }
      }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:30,代码来源:SecurityCallStack.cs

示例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;
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:59,代码来源:test-inline-call-stack.cs

示例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));
        }
开发者ID:jonasrh,项目名称:dot-omegle,代码行数:11,代码来源:Util.cs

示例7: GetLogger

        public ILogger GetLogger()
        {
            StackFrame frame = new StackFrame(1, false);

            Type t = frame.GetMethod() == null ? GetType() : frame.GetMethod().DeclaringType;

            return GetLogger(t);
        }
开发者ID:abelsilva,项目名称:nugetory,代码行数:8,代码来源:LogFactory.cs

示例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 ;
    }
开发者ID:buguen,项目名称:wsnpy,代码行数:10,代码来源:net.cs

示例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;
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:14,代码来源:Log.cs

示例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();
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:11,代码来源:DebugLogger.cs

示例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());
        }
开发者ID:TIT-tech,项目名称:OPM_BO,代码行数:13,代码来源:DLLLogFile.cs

示例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();
        }
开发者ID:autocar,项目名称:ircddotnet,代码行数:15,代码来源:Logger.cs

示例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();
        }
开发者ID:aloneguid,项目名称:logmagic,代码行数:32,代码来源:MethodNameEnricher.cs

示例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 + "$"));
                    }
                );
        }
开发者ID:smhabdoli,项目名称:NBehave,代码行数:26,代码来源:StoryRunnerFilterSpecs.cs

示例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);
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:27,代码来源:ScopeLogger.cs


注:本文中的System.Diagnostics.StackFrame.GetMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。