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


C# MethodDefinition.ToString方法代码示例

本文整理汇总了C#中Mono.Cecil.MethodDefinition.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.ToString方法的具体用法?C# MethodDefinition.ToString怎么用?C# MethodDefinition.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.MethodDefinition的用法示例。


在下文中一共展示了MethodDefinition.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetIlSource

		// internal stuff

		// shamelessly copied from http://evain.net/public/cecil_il_sample_source.html
		// thanks again Jb!
		private string GetIlSource (MethodDefinition method)
		{
			if (method.Body == null) {
				// it can either be abstract or extern (e.g. icall)
				if (method.IsAbstract)
					return "abstract " + method.ToString ();
				else
					return "extern " + method.ToString ();
			}

			StringBuilder il = new StringBuilder ();
			il.AppendFormat ("{0}{1}{{{1}", method.ToString (), Environment.NewLine);
			il.AppendFormat ("\t// code size : {0}{1}", method.Body.CodeSize, Environment.NewLine);
			il.AppendFormat ("\t.maxstack {0}{1}", method.Body.MaxStack, Environment.NewLine);
			il.Append ("\t.locals (");
			for (int i = 0; i < method.Body.Variables.Count; i++) {
				if (i > 0)
					il.Append (", ");
				VariableDefinition var = method.Body.Variables[i];
				il.Append (string.Concat (var.VariableType.FullName, " ", var.Name));
			}
			il.AppendFormat ("){0}", Environment.NewLine);

			foreach (Instruction instr in method.Body.Instructions) {
				il.AppendFormat ("\tIL_{0}: {1} ", instr.Offset.ToString ("X4"), instr.OpCode.Name);
				switch (instr.OpCode.OperandType) {
				case OperandType.InlineNone:
					break;
				case OperandType.InlineSwitch:
					int[] brchs = instr.Operand as int[];
					for (int i = 0; i < brchs.Length; i++) {
						if (i > 0)
							il.Append (", ");
						il.AppendFormat ("\tIL_{0}", brchs[i].ToString ("X4"));
					}
					il.Append (Environment.NewLine);
					break;
				case OperandType.ShortInlineBrTarget:
				case OperandType.InlineBrTarget:
					Mono.Cecil.Cil.Instruction ins = (instr.Operand as Mono.Cecil.Cil.Instruction);
					il.AppendFormat ("\tIL_{0}", ins.Offset.ToString ("X4"));
					break;
				case OperandType.InlineString:
					il.AppendFormat ("\"{0}\"", instr.Operand);
					break;
				default:
					il.Append (instr.Operand);
					break;
				}
				il.Append (Environment.NewLine);
			}
			il.AppendFormat ("}}{0}", Environment.NewLine);
			return il.ToString ();
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:58,代码来源:IlasmSourceVisualizer.cs

示例2: CheckMethod

		public RuleResult CheckMethod (MethodDefinition method)
		{
			if (method.Body == null)
				return RuleResult.DoesNotApply;

			CFG cfg = new CFG (method);

			// requires -v -v
			if (Runner.VerbosityLevel > 0) {
				Trace.WriteLine(string.Empty);
				Trace.WriteLine("-------------------------------------");
				Trace.WriteLine(method.ToString());
				if (Runner.VerbosityLevel > 2)
					cfg.PrintDot ();
			}

			NonNullAttributeCollector nnaCollector = new NonNullAttributeCollector();
			NullDerefAnalysis analysis = new NullDerefAnalysis (method, nnaCollector, Runner);
			analysis.Verbose = Runner.VerbosityLevel > 1;

			Dataflow dataflow = new Dataflow (cfg, analysis);
			analysis.Verbose = Runner.VerbosityLevel > 1;
			dataflow.Compute ();

			return Runner.CurrentRuleResult;
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:26,代码来源:NullDerefRule.cs

示例3: Location

		public Location Location(MethodDefinition method, int offset, string details)
		{			
			var info = DoFindFileLine(method, offset);

			Location location = new Location();
			location.File = info.First;			
			location.Line = info.Second;
			location.Name = "Method: " + method.ToString();			
			location.Offset = offset;
			location.Details = details;
					
			return location;
		}
开发者ID:dbremner,项目名称:smokey,代码行数:13,代码来源:SymbolTable.cs

示例4: VisitMethod

		public void VisitMethod(MethodDefinition method)
		{			
			if (m_needsCheck && !m_failed)
			{
				MethodAttributes access = method.Attributes & MethodAttributes.MemberAccessMask;
				if (access == MethodAttributes.Public && method.IsSpecialName)
				{
					if (method.Name == "op_Explicit" || method.Name == "op_Implicit")
					{	
						string name = method.ReturnType.ReturnType.Name;
						if (!DoHas("To" + name + "Type"))
						{
							m_details = method.ToString();
							m_failed = true;
						}
					}
				}
			}			
		}
开发者ID:dbremner,项目名称:smokey,代码行数:19,代码来源:CastOpAlternativeRule.cs

示例5: VMethod

        public VMethod(VClass vclass, MethodDefinition methodDefinition)
        {
            VClass = vclass;
            MethodDefinition = methodDefinition;
            var fn = MethodDefinition.ToString();
            FullName = fn.Substring(fn.IndexOf(' ') + 1);
            if (!MethodDefinition.HasBody)
                return;

            InstructionCount = MethodDefinition.Body.Instructions.Count;
            VClass.InstructionCount += InstructionCount;
            foreach (var instruction in MethodDefinition.Body.Instructions)
                if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt)
                {
                    var methodCall = instruction.Operand as MethodReference;
                    if (methodCall == null )
                        continue;
                    var name = methodCall.FullName;
                    name = name.Substring(name.IndexOf(' ') + 1);
                    if (!Calling.Contains(name))
                        Calling.Add(name);
                }
        }
开发者ID:danbystrom,项目名称:VisionQuest,代码行数:23,代码来源:VMethod.cs

示例6: Url

		public static string Url (MethodDefinition m)
		{
			if ((m.Attributes & MethodAttributes.Public) == 0)
				return String.Empty;

			string fullname = m.ToString ();
			string monodoc = "http://www.go-mono.com/docs/monodoc.ashx?link={0}";
			// remove return type
			string method = fullname.Substring (fullname.IndexOf (' ') + 1);
			// replace :: by .
			int index = method.IndexOf ("::");
			string classname = method.Substring (0, index);
			string methodname = method.Substring (index + 2);
			if (methodname.StartsWith ("get_") || methodname.StartsWith ("set_"))
			{
				// property - remove get_|set_ and ()
//				string property = methodname.Substring (4, methodname.Length - 6);
				string url = String.Format ("P:{0}.{1}", classname, methodname.Substring (4, methodname.Length - 6));
				monodoc = String.Format (monodoc, url);
			} else {
				// method
				string url = String.Format ("M:{0}.{1}", classname, methodname);
				monodoc = String.Format (monodoc, url);
			}
			return String.Concat (",URL=\"", monodoc, "\"");
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:26,代码来源:CallerAnalysisVisualizer.cs

示例7: BuildDotFile

		private Digraph BuildDotFile (MethodDefinition method)
		{
			Digraph dot = new Digraph ();
			dot.Name = "AssemblyDependencies";
			dot.AutoConcentrate = true;
			dot.Label = method.ToString ();
			dot.LabelLoc = "t";
			dot.FontName = "tahoma";
			dot.FontSize = 10;

			bool hasInternalCall = false;
			bool hasPublic = false;
			bool hasProtected = false;
			bool hasSpecial = false;
			foreach (Cluster c in clusters.Values) {
				hasInternalCall |= c.HasInternalCall;
				hasPublic |= c.HasPublic;
				hasProtected |= c.HasProtected;
				hasSpecial |= c.HasSpecial;

				c.AddToDot (dot);
			}
			
			if (hasInternalCall)
				dot.Nodes.Add (new Node ("runtime"));
//			if (hasPublic)
//				dot.AppendFormat ("\t\"any public code\";{0}", Environment.NewLine);
//			if (hasProtected)
//				dot.AppendFormat ("\t\"any inherited code\";{0}", Environment.NewLine);
			if (hasSpecial)
				dot.Nodes.Add (new Node ("unknown caller"));

			// calls
			if (extra_edges.Count > 0) {
				foreach (Edge edge in extra_edges) {
					dot.Edges.Add (edge);
				}
			}
			
			return dot;
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:41,代码来源:CallerAnalysisVisualizer.cs

示例8: InitBody


//.........这里部分代码省略.........
                dgGeneral.SuspendLayout();

                _dtBody.Rows.Clear();
                _dtGeneral.Rows.Clear();
                _dtVariable.Rows.Clear();

                if (md == null)
                {
                    _currentMethod = null;
                    return;
                }

                _dtBody.BeginLoadData();
                _dtGeneral.BeginLoadData();
                _dtVariable.BeginLoadData();

                if (md.HasBody && md.Body.Instructions.Count > 100)
                {
                    wc = new SimpleWaitCursor();
                }

                _currentMethod = md;

                InitDataTableGeneral(md);
                InitDataTableBody(md);
                InitDataTableVariable(md);

                if (dgBody.DataSource == null)
                    dgBody.DataSource = _dtBody;

                if (dgGeneral.DataSource == null)
                    dgGeneral.DataSource = _dtGeneral;

                if (dgVariable.DataSource == null)
                    dgVariable.DataSource = _dtVariable;

                _dtBody.EndLoadData();
                _dtGeneral.EndLoadData();
                _dtVariable.EndLoadData();

                if (md.HasBody)
                {
                    Collection<ExceptionHandler> ehc = md.Body.ExceptionHandlers;

                    //check invalid exception handler
                    for (int i = dgBody.Rows.Count - 2; i >= 0; i--)
                    {
                        DataGridViewRow row = dgBody.Rows[i];
                        int ehIndex = GetExceptionHandlerIndex(row);
                        if (ehIndex >= 0)
                        {
                            if (!DeobfUtils.IsValidExceptionHandler(ehc[ehIndex]))
                            {
                                row.DefaultCellStyle.ForeColor = Color.Red;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                _form.SearchHandler.LastHighlightIndex = 0;

                if (_markBlocks)
                    MarkBlocks();

                if (_currentRowIndex >= 0)
                {
                    SetCurrentRow(_currentRowIndex);
                    _currentRowIndex = -1;
                }
                if (_currentVarIndex >= 0)
                {
                    SetCurrentVariable(_currentVarIndex);
                    _currentVarIndex = -1;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                dgBody.ResumeLayout();
                dgGeneral.ResumeLayout();
                tabDetails.ResumeLayout();

                if (wc != null) wc.Dispose();

                if (_currentMethod != null)
                {
                    DateTime endTime = DateTime.Now;
                    _form.SetStatusText(String.Format("{0} (load time: {1} seconds)",
                        _currentMethod.ToString(),
                        (endTime - startTime).TotalSeconds));
                }
            }
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:101,代码来源:ClassEditBodyGridHandler.cs

示例9: IsMatch

        public bool IsMatch(MethodDefinition method)
        {
            if (IgnoreSystemMethods && IsSystemMethod(method))
                return true;
            if(IgnorePInvokeMethods && method.IsPInvokeImpl)
                return true;
            if (IsExceedMaxInstructionCount(method))
                return true;

            if (method.ReturnType.FullName == "System.String")
            {
                if (IgnoreMethodsWithoutParam && method.Parameters.Count == 0)
                    return true;
            }

            string name = method.ToString();
            if (IsMatch(name))
                return true;
            name = "0x" + TokenUtils.GetFullMetadataTokenString(method.MetadataToken);
            if (IsMatch(name))
                return true;
            return false;
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:23,代码来源:IgnoredMethodFile.cs

示例10: ProcessMethod

        private void ProcessMethod(MethodDefinition method)
        {
            if (method.HasBody)
            {
                ILProcessor ilProcessor = method.Body.GetILProcessor();

                //process every instruction of the methods body
                for (int n = 0; n < ilProcessor.Body.Instructions.Count; n++) //foreach won't work because iterator length is bigger than count??
                {
                    var instruction = ilProcessor.Body.Instructions[n];

                    //check whether the instruction is a call to a method
                    if (instruction.OpCode.Code == Code.Call && instruction.Operand is MethodReference)
                    {
                        //get the called method
                        MethodReference methodDescription = (MethodReference)instruction.Operand;
                        //get the attributes of the called method
                        var attributes = GetAttributes(methodDescription.Resolve());

                        //check whether the called method is marked with the given calli attribute
                        if (attributes.Contains(_calliAttributeName))
                        {
                            MessageIntegration.Info("Patching [{0}] @ [{1}].", method.ToString(), instruction.ToString());
                            if (!method.Name.EndsWith("Native"))
                                MessageIntegration.Info(String.Format("CallI-Comimport Methodnames should end with a \"Native\". Method: \"{0}\".", method.FullName));

                            //create a callsite for the calli instruction using stdcall calling convention
                            var callSite = new CallSite(methodDescription.ReturnType)
                            {
                                CallingConvention = MethodCallingConvention.StdCall
                            };

                            //iterate through every parameter of the original method-call
                            for (int j = 0; j < methodDescription.Parameters.Count - 1; j++) //foreach won't work because iterator length is bigger than count??
                            {
                                var p = methodDescription.Parameters[j];
                                if (p.ParameterType.FullName == "System.Boolean")
                                {
                                    MessageIntegration.WriteWarning("Native bool has a size of 4 bytes. Make sure to use a 16bit Integer for \"VARIANT_BOOL\" and a 32bit Integer for \"BOOL\".", "CI0001");
                                }

                                //append every parameter of the method-call to the callsite of the calli instruction
                                callSite.Parameters.Add(p);
                            }

                            //create a calli-instruction including the just built callSite
                            var calliInstruction = ilProcessor.Create(OpCodes.Calli, callSite);
                            //replace the method-call by the calli-instruction
                            ilProcessor.Replace(instruction, calliInstruction);

                            _replacedCallsCount++;
                        }
                    }
                }
            }
        }
开发者ID:CheViana,项目名称:AudioLab,代码行数:56,代码来源:AssemblyPatcher.cs

示例11: CheckMethod

		private void CheckMethod (MethodDefinition method)
		{
			if (!method.HasBody)
				return;

			// avoid looping if we're sure there's no call in the method
			if (!OpCodeBitmask.Calls.Intersect (OpCodeEngine.GetBitmask (method)))
				return;

			string method_name = method.ToString ();
			// check to avoid constructors calling recursive methods
			if (stack.Contains (method_name))
				return;

			// check constructor for virtual method calls
			foreach (Instruction current in method.Body.Instructions) {
				switch (current.OpCode.Code) {
				case Code.Call:
				case Code.Callvirt:
					// we recurse into normal calls since they might be calling virtual methods
					MethodDefinition md = (current.Operand as MethodDefinition);
					if (md == null || md.IsConstructor || !md.HasThis)
						continue;

					// check that the method is it this class or a subclass
					if (!IsSubsclass (md.DeclaringType, method.DeclaringType))
						continue;

					// check that we're not calling the method on another object
					if (!IsCallFromInstance (current.Previous, md.Parameters.Count))
						continue;

					if (md.IsVirtual && !md.IsFinal) {
						string s = stack.Count == 0 ? method_name : stack.Aggregate ((a1, a2) => a1 + ", " + Environment.NewLine + a2);
						s = String.Format ("Calling a virtual method, '{0}' from {1}.", md, s);
						Runner.Report (method, current, Severity.High, Confidence.High, s);
					} else {
						stack.Push (method_name);
						CheckMethod (md);
						stack.Pop ();
					}
					break;
				}
			}
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:45,代码来源:ConstructorShouldNotCallVirtualMethodsRule.cs

示例12: OnMethodSelection

		private void OnMethodSelection (MethodDefinition md)
		{
			objectLabel.Text = md.ToString ();
			// very useful for debugging
			textview.Buffer.Text = String.Empty;
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:6,代码来源:MainWindow.cs

示例13: GetSignature

 static string GetSignature(MethodDefinition method)
 {
     return method.ToString ().Replace ("<", "[").Replace (">", "]");
 }
开发者ID:huyunozzpc,项目名称:NETPack,代码行数:4,代码来源:XApiReader.cs

示例14: CheckIfBaseDisposeIsCalled

		private void CheckIfBaseDisposeIsCalled (MethodDefinition method, MethodDefinition baseMethod)
		{
			bool found = false;

			if (method.HasBody) {
				OpCodeBitmask bitmask = OpCodeEngine.GetBitmask (method);
				if (bitmask.Get (Code.Ldarg_0) && (OpCodeBitmask.Calls.Intersect (bitmask))) {

					//Check for a call to base.Dispose();
					foreach (Instruction ins in method.Body.Instructions) {
						if (ins.OpCode.Code != Code.Ldarg_0) //ldarg_0 (this)
							continue;

						Instruction call = ins.Next; //call baseMethod
						if (call == null)
							continue;
						if (call.OpCode.Code != Code.Call && call.OpCode.Code != Code.Callvirt)
							continue;
						MethodReference calledMethod = (MethodReference) call.Operand;
						if (calledMethod.ToString () != baseMethod.ToString ())
							continue;
						found = true;
					}
				}
			}

			if (!found) {
				string s = String.Format ("{0} should call base.Dispose().", method.ToString ());
				Runner.Report (method, Severity.Medium, Confidence.High, s);
			}
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:31,代码来源:DisposableFieldsShouldBeDisposedRule.cs

示例15: GetIlSourceAsDot

		// internal stuff

		private Digraph GetIlSourceAsDot (MethodDefinition method)
		{
			Digraph dot = new Digraph ();
			dot.Name = "IL";
			dot.Label = method.ToString ();
			dot.LabelLoc = "t";
			dot.FontName = "tahoma";
			dot.FontSize = 10;

			if (method.Body != null) {
				List<IlInstruction> instructions = new List<IlInstruction> ();

				foreach (Instruction instr in method.Body.Instructions) {
					IlInstruction i = new IlInstruction (instr);
					i.Name = instr.OpCode.Name;

					switch (instr.OpCode.OperandType) {
					case OperandType.InlineNone:
						break;
					case OperandType.InlineSwitch:
						int[] brchs = instr.Operand as int[];
						i.Calls = new List<string> (brchs.Length);

						for (int j = 0; j < brchs.Length; j++) {
							string switchtarget = String.Format ("IL_{0}", brchs[j].ToString ("X4"));
							i.Name += String.Format ("\t{0}{1}", (j > 0) ? ", " : String.Empty, switchtarget);
							i.Calls.Add (switchtarget);
						}
						break;
					case OperandType.ShortInlineBrTarget:
					case OperandType.InlineBrTarget:
						Instruction ins = (instr.Operand as Instruction);
						string target = String.Format ("IL_{0}", ins.Offset.ToString ("X4"));
						i.Name = String.Format ("{0} {1}", i.Name, target);
						i.Calls = new List<string> (1);
						i.Calls.Add (target);
						break;
					case OperandType.InlineString:
						i.Name = String.Format ("{0} '{1}'", i.Name, instr.Operand);
						break;
					default:
						i.Name = String.Format ("{0} {1}", i.Name, instr.Operand);
						break;
					}

					// add instruction
					instructions.Add (i);
				}

				// build dot for each instructions
				
				// first add the nodes
				foreach (IlInstruction i in instructions) {
					Node n = i.GetNode (true);
					dot.Nodes.Add (n);
				}
				// then add the edges
				for (int j = 0; j < instructions.Count; j++) {
					IlInstruction i = instructions[j];
					Node n = i.GetNode (false);

					if (i.Calls != null) {
						foreach (string callee in i.Calls) {
							IlInstruction target = FindCallee (callee, instructions);
							Node t = target.GetNode (false);
							Edge e = new Edge (n, t);

							string label = target.Label;
							if (label.Length > 0)
								e.Attributes["label"] = label;

							dot.Edges.Add (e);
						}
					}
					// by default execution continues to the next instruction
					// unless - we have an unconditional branch or it's the last instruction
					if ((j < instructions.Count - 1) && !i.IsUnconditionalBranch ()) {
						IlInstruction next = (IlInstruction)instructions[j + 1];
						Edge e = new Edge (n, next.GetNode (false));
						string label = next.Label;
						if (label.Length > 0)
							e.Attributes["label"] = label;
						dot.Edges.Add (e);
					}
				}
			}

			return dot;
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:91,代码来源:IlasmGraphVisualizer.cs


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