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


C# ITextOutput.WriteDefinition方法代码示例

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


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

示例1: DecompileMethod

		public override void DecompileMethod(MethodDef method, ITextOutput output, DecompilationOptions options)
		{
			WriteComment(output, "Method: ");
			output.WriteDefinition(IdentifierEscaper.Escape(method.FullName), method, TextTokenType.Comment, false);
			output.WriteLine();

			if (!method.HasBody) {
				return;
			}
			
			StartKeywordBlock(output, ".body", method);

			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
			ilMethod.Body = astBuilder.Build(method, inlineVariables, context);
			
			if (abortBeforeStep != null) {
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			if (context.CurrentMethodIsAsync) {
				output.Write("async", TextTokenType.Keyword);
				output.Write('/', TextTokenType.Operator);
				output.WriteLine("await", TextTokenType.Keyword);
			}
			
			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(IdentifierEscaper.Escape(v.Name), v, v.IsParameter ? TextTokenType.Parameter : TextTokenType.Local);
				if (v.Type != null) {
					output.WriteSpace();
					output.Write(':', TextTokenType.Operator);
					output.WriteSpace();
					if (v.IsPinned) {
						output.Write("pinned", TextTokenType.Keyword);
						output.WriteSpace();
					}
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				if (v.IsGenerated) {
					output.WriteSpace();
					output.Write('[', TextTokenType.Operator);
					output.Write("generated", TextTokenType.Keyword);
					output.Write(']', TextTokenType.Operator);
				}
				output.WriteLine();
			}
			
			var memberMapping = new MemberMapping(method);
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output, memberMapping);
				if (!node.WritesNewLine)
					output.WriteLine();
			}
			output.AddDebugSymbols(memberMapping);
			EndKeywordBlock(output);
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:59,代码来源:ILAstLanguage.cs

示例2: WriteTo

		public static void WriteTo(this Instruction instruction, ITextOutput writer, Func<OpCode, string> getOpCodeDocumentation)
		{
			writer.WriteDefinition(DnlibExtensions.OffsetToString(instruction.GetOffset()), instruction, TextTokenType.Label, false);
			writer.Write(':', TextTokenType.Operator);
			writer.WriteSpace();
			writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, TextTokenType.OpCode);
			if (instruction.Operand != null) {
				writer.WriteSpace();
				if (instruction.OpCode == OpCodes.Ldtoken) {
					var member = instruction.Operand as IMemberRef;
					if (member != null && member.IsMethod) {
						writer.Write("method", TextTokenType.Keyword);
						writer.WriteSpace();
					}
					else if (member != null && member.IsField) {
						writer.Write("field", TextTokenType.Keyword);
						writer.WriteSpace();
					}
				}
				WriteOperand(writer, instruction.Operand);
			}
			if (getOpCodeDocumentation != null) {
				var doc = getOpCodeDocumentation(instruction.OpCode);
				if (doc != null) {
					writer.Write("\t", TextTokenType.Text);
					writer.Write("// " + doc, TextTokenType.Comment);
				}
			}
		}
开发者ID:lisong521,项目名称:dnSpy,代码行数:29,代码来源:DisassemblerHelpers.cs

示例3: DecompileMethod

		public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
		{
			if (!method.HasBody) {
				return;
			}
			
			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			ilMethod.Body = astBuilder.Build(method, inlineVariables);
			
			if (abortBeforeStep != null) {
				DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(v.Name, v);
				if (v.Type != null) {
					output.Write(" : ");
					if (v.IsPinned)
						output.Write("pinned ");
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				output.WriteLine();
			}
			output.WriteLine();
			
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output);
				output.WriteLine();
			}
		}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:34,代码来源:ILAstLanguage.cs

示例4: WriteTo

		public static void WriteTo(this Instruction instruction, ITextOutput writer)
		{
			writer.WriteDefinition(CecilExtensions.OffsetToString(instruction.Offset), instruction);
			writer.Write(": ");
			writer.WriteReference(instruction.OpCode.Name, instruction.OpCode);
			if(null != instruction.Operand) {
				writer.Write(' ');
				WriteOperand(writer, instruction.Operand);
			}
		}
开发者ID:constructor-igor,项目名称:cudafy,代码行数:10,代码来源:DisassemblerHelpers.cs

示例5: WriteTo

		public static void WriteTo(this Instruction instruction, ITextOutput writer)
		{
			writer.WriteDefinition(CecilExtensions.OffsetToString(instruction.Offset), instruction);
			writer.Write(": ");
			writer.WriteReference(instruction.OpCode.Name, instruction.OpCode);
			if (instruction.Operand != null) {
				writer.Write(' ');
				if (instruction.OpCode == OpCodes.Ldtoken) {
					if (instruction.Operand is MethodReference)
						writer.Write("method ");
					else if (instruction.Operand is FieldReference)
						writer.Write("field ");
				}
				WriteOperand(writer, instruction.Operand);
			}
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:16,代码来源:DisassemblerHelpers.cs

示例6: WriteTo

		public static void WriteTo(this Instruction instruction, MethodDef method, CilBody body, ITextOutput writer)
		{
			writer.WriteDefinition(dnlibExtensions.OffsetToString(instruction.Offset), instruction, true);
			writer.Write(": ");
			writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, true);
			if (instruction.Operand != null) {
				writer.Write(' ');
				if (instruction.OpCode == OpCodes.Ldtoken) {
					if (dnlibExtensions.IsMethod(instruction.Operand))
						writer.WriteKeyword("method ");
					else if (dnlibExtensions.IsField(instruction.Operand))
						writer.WriteKeyword("field ");
				}
				WriteOperand(writer, instruction.Operand);
			}
			else if (method != null && body != null) {
				switch (instruction.OpCode.Code) {
					case Code.Ldloc_0:
					case Code.Ldloc_1:
					case Code.Ldloc_2:
					case Code.Ldloc_3:
						writer.WriteComment("  // ");
						var local = instruction.GetLocal(body.Variables);
						if (local != null)
							WriteOperand(writer, local);
						break;

					case Code.Ldarg_0:
					case Code.Ldarg_1:
					case Code.Ldarg_2:
					case Code.Ldarg_3:
						writer.WriteComment("  // ");
						var arg = instruction.GetParameter(method.Parameters);
						if (arg != null)
							WriteOperand(writer, arg);
						break;
				}
			}
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:39,代码来源:DisassemblerHelpers.cs

示例7: DecompileField

		public override void DecompileField(FieldDef field, ITextOutput output, DecompilationOptions options)
		{
			output.WriteReference(IdentifierEscaper.Escape(field.FieldType.GetFullName()), field.FieldType.ToTypeDefOrRef(), TextTokenHelper.GetTextTokenType(field.FieldType));
			output.WriteSpace();
			output.WriteDefinition(IdentifierEscaper.Escape(field.Name), field, TextTokenHelper.GetTextTokenType(field), false);
			var c = field.Constant;
			if (c != null) {
				output.WriteSpace();
				output.Write('=', TextTokenType.Operator);
				output.WriteSpace();
				if (c.Value == null)
					output.Write("null", TextTokenType.Keyword);
				else {
					switch (c.Type) {
					case ElementType.Boolean:
						if (c.Value is bool)
							output.Write((bool)c.Value ? "true" : "false", TextTokenType.Keyword);
						else
							goto default;
						break;

					case ElementType.Char:
						output.Write(string.Format("'{0}'", c.Value), TextTokenType.Char);
						break;

					case ElementType.I1:
					case ElementType.U1:
					case ElementType.I2:
					case ElementType.U2:
					case ElementType.I4:
					case ElementType.U4:
					case ElementType.I8:
					case ElementType.U8:
					case ElementType.R4:
					case ElementType.R8:
					case ElementType.I:
					case ElementType.U:
						output.Write(string.Format("{0}", c.Value), TextTokenType.Number);
						break;

					case ElementType.String:
						output.Write(string.Format("{0}", c.Value), TextTokenType.String);
						break;

					default:
						output.Write(string.Format("{0}", c.Value), TextTokenType.Text);
						break;
					}
				}
			}
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:51,代码来源:ILAstLanguage.cs

示例8: StartKeywordBlock

		void StartKeywordBlock(ITextOutput output, string keyword, IMemberDef member)
		{
			output.Write(keyword, TextTokenType.Keyword);
			output.WriteSpace();
			output.WriteDefinition(IdentifierEscaper.Escape(member.Name), member, TextTokenHelper.GetTextTokenType(member), false);
			output.WriteSpace();
			output.WriteLeftBrace();
			output.WriteLine();
			output.Indent();
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:10,代码来源:ILAstLanguage.cs

示例9: WriteTo

        public static void WriteTo(this Instruction instruction, ITextOutput writer, DisassemblerOptions options, uint baseRva, long baseOffs, IInstructionBytesReader byteReader, MethodDef method)
        {
            if (options != null && (options.ShowTokenAndRvaComments || options.ShowILBytes)) {
                writer.Write("/* ", TextTokenType.Comment);

                bool needSpace = false;

                if (options.ShowTokenAndRvaComments) {
                    ulong fileOffset = (ulong)baseOffs + instruction.Offset;
                    writer.WriteReference(string.Format("0x{0:X8}", fileOffset), new AddressReference(options.OwnerModule == null ? null : options.OwnerModule.Location, false, fileOffset, (ulong)instruction.GetSize()), TextTokenType.Comment, false);
                    needSpace = true;
                }

                if (options.ShowILBytes) {
                    if (needSpace)
                        writer.Write(' ', TextTokenType.Comment);
                    if (byteReader == null)
                        writer.Write("??", TextTokenType.Comment);
                    else {
                        int size = instruction.GetSize();
                        for (int i = 0; i < size; i++) {
                            var b = byteReader.ReadByte();
                            if (b < 0)
                                writer.Write("??", TextTokenType.Comment);
                            else
                                writer.Write(string.Format("{0:X2}", b), TextTokenType.Comment);
                        }
                        // Most instructions should be at most 5 bytes in length, but use 6 since
                        // ldftn/ldvirtftn are 6 bytes long. The longest instructions are those with
                        // 8 byte operands, ldc.i8 and ldc.r8: 9 bytes.
                        const int MIN_BYTES = 6;
                        for (int i = size; i < MIN_BYTES; i++)
                            writer.Write("  ", TextTokenType.Comment);
                    }
                }

                writer.Write(" */", TextTokenType.Comment);
                writer.WriteSpace();
            }
            writer.WriteDefinition(DnlibExtensions.OffsetToString(instruction.GetOffset()), new InstructionReference(method, instruction), TextTokenType.Label, false);
            writer.Write(':', TextTokenType.Operator);
            writer.WriteSpace();
            writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, TextTokenType.OpCode);
            if (instruction.Operand != null) {
                int count = OPERAND_ALIGNMENT - instruction.OpCode.Name.Length;
                if (count <= 0)
                    count = 1;
                writer.Write(spaces[count], TextTokenType.Text);
                if (instruction.OpCode == OpCodes.Ldtoken) {
                    var member = instruction.Operand as IMemberRef;
                    if (member != null && member.IsMethod) {
                        writer.Write("method", TextTokenType.Keyword);
                        writer.WriteSpace();
                    }
                    else if (member != null && member.IsField) {
                        writer.Write("field", TextTokenType.Keyword);
                        writer.WriteSpace();
                    }
                }
                WriteOperand(writer, instruction.Operand, method);
            }
            if (options != null && options.GetOpCodeDocumentation != null) {
                var doc = options.GetOpCodeDocumentation(instruction.OpCode);
                if (doc != null) {
                    writer.Write("\t", TextTokenType.Text);
                    writer.Write("// " + doc, TextTokenType.Comment);
                }
            }
        }
开发者ID:gsong2014,项目名称:dnSpy,代码行数:69,代码来源:DisassemblerHelpers.cs

示例10: WriteShort

        public override void WriteShort(ITextOutput output, ILanguage language, bool showOffset)
        {
            var smartOutput = output as ISmartTextOutput;
            if (smartOutput != null) {
                language.WriteCommentBegin(output, true);
                output.WriteOffsetComment(this, showOffset);
                smartOutput.AddUIElement(() => {
                    return new System.Windows.Controls.Image {
                        Source = imageSource,
                    };
                });
                output.Write(" = ", TextTokenKind.Comment);
                output.WriteDefinition(NameUtils.CleanName(Name), this, TextTokenKind.Comment);
                language.WriteCommentEnd(output, true);
                output.WriteLine();
                return;
            }

            base.WriteShort(output, language, showOffset);
        }
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:20,代码来源:ImageResourceNode.cs

示例11: Decompile

		public virtual void Decompile(Language language, ITextOutput output) {
			language.WriteComment(output, string.Empty);
			output.WriteOffsetComment(this);
			output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
			string extra = null;
			if (r.ResourceType == ResourceType.AssemblyLinked)
				extra = ((AssemblyLinkedResource)r).Assembly.FullName;
			else if (r.ResourceType == ResourceType.Linked) {
				var file = ((LinkedResource)r).File;
				extra = string.Format("{0}, {1}, {2}", file.Name, file.ContainsNoMetaData ? "ContainsNoMetaData" : "ContainsMetaData", NumberVMUtils.ByteArrayToString(file.HashValue));
			}
			else if (r.ResourceType == ResourceType.Embedded)
				extra = string.Format("{0} bytes", ((EmbeddedResource)r).Data.Length);
			output.Write(string.Format(" ({0}{1}, {2})", extra == null ? string.Empty : string.Format("{0}, ", extra), r.ResourceType, r.Attributes), TextTokenType.Comment);
			output.WriteLine();
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:16,代码来源:ResourceTreeNode.cs

示例12: Decompile

 public virtual void Decompile(Language language, ITextOutput output)
 {
     language.WriteComment(output, string.Empty);
     output.WriteOffsetComment(this);
     output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
     output.Write(string.Format(" = {0}", ValueString), TextTokenType.Comment);
     output.WriteLine();
 }
开发者ID:gsong2014,项目名称:dnSpy,代码行数:8,代码来源:ResourceElementTreeNode.cs

示例13: WriteShort

 public virtual void WriteShort(ITextOutput output, ILanguage language, bool showOffset)
 {
     language.WriteCommentBegin(output, true);
     output.WriteOffsetComment(this, showOffset);
     output.WriteDefinition(NameUtils.CleanName(Name), this, TextTokenKind.Comment);
     output.Write(string.Format(" = {0}", ValueString), TextTokenKind.Comment);
     language.WriteCommentEnd(output, true);
     output.WriteLine();
 }
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:9,代码来源:ResourceElementNode.cs

示例14: Decompile

 public virtual void Decompile(Language language, ITextOutput output)
 {
     language.WriteComment(output, string.Empty);
     if (Options.DecompilerSettingsPanel.CurrentDecompilerSettings.ShowTokenAndRvaComments) {
         long fo = FileOffset;
         if (fo != 0)
             output.Write(string.Format("0x{0:X8}: ", fo), TextTokenType.Comment);
     }
     output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
     output.Write(string.Format(" = {0}", ValueString), TextTokenType.Comment);
     output.WriteLine();
 }
开发者ID:damnya,项目名称:dnSpy,代码行数:12,代码来源:ResourceElementTreeNode.cs

示例15: Decompile

 public virtual void Decompile(Language language, ITextOutput output)
 {
     language.WriteComment(output, string.Empty);
     if (Options.DecompilerSettingsPanel.CurrentDecompilerSettings.ShowTokenAndRvaComments) {
         long fo = FileOffset;
         if (fo != 0)
             output.Write(string.Format("0x{0:X8}: ", fo), TextTokenType.Comment);
     }
     output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
     string extra = null;
     if (r.ResourceType == ResourceType.AssemblyLinked)
         extra = ((AssemblyLinkedResource)r).Assembly.FullName;
     else if (r.ResourceType == ResourceType.Linked) {
         var file = ((LinkedResource)r).File;
         extra = string.Format("{0}, {1}, {2}", file.Name, file.ContainsNoMetaData ? "ContainsNoMetaData" : "ContainsMetaData", AsmEditor.NumberVMUtils.ByteArrayToString(file.HashValue));
     }
     output.Write(string.Format(" ({0}{1}, {2})", extra == null ? string.Empty : string.Format("{0}, ", extra), r.ResourceType, r.Attributes), TextTokenType.Comment);
     output.WriteLine();
 }
开发者ID:damnya,项目名称:dnSpy,代码行数:19,代码来源:ResourceTreeNode.cs


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