本文整理汇总了C#中ITextOutput.WriteComment方法的典型用法代码示例。如果您正苦于以下问题:C# ITextOutput.WriteComment方法的具体用法?C# ITextOutput.WriteComment怎么用?C# ITextOutput.WriteComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextOutput
的用法示例。
在下文中一共展示了ITextOutput.WriteComment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
}
示例2: WriteOperand
public static void WriteOperand(ITextOutput writer, object operand)
{
if (operand == null)
throw new ArgumentNullException("operand");
Instruction targetInstruction = operand as Instruction;
if (targetInstruction != null) {
WriteOffsetReference(writer, targetInstruction);
return;
}
Instruction[] targetInstructions = operand as Instruction[];
if (targetInstructions != null) {
WriteLabelList(writer, targetInstructions);
return;
}
Local local = operand as Local;
if (local != null) {
if (string.IsNullOrEmpty(local.Name))
writer.WriteReference("[" + local.Index.ToString() + "]", local, true);
else
writer.WriteReference(Escape(local.Name), local, true);
return;
}
Parameter param = operand as Parameter;
if (param != null) {
if (string.IsNullOrEmpty(param.Name))
writer.WriteReference("[" + param.Index.ToString() + "]", param, true);
else
writer.WriteReference(Escape(param.Name), param, true);
return;
}
IMethod methodRef = operand as IMethod;
if (methodRef != null && dnlibExtensions.IsMethod(methodRef)) {
methodRef.WriteTo(writer);
writer.WriteComment(" // 0x" + methodRef.MDToken.Raw.ToString("x8"));
return;
}
ITypeDefOrRef typeRef = operand as ITypeDefOrRef;
if (typeRef != null) {
typeRef.WriteTo(writer, ILNameSyntax.TypeName);
writer.WriteComment(" // 0x" + typeRef.MDToken.Raw.ToString("x8"));
return;
}
IField fieldRef = operand as IField;
if (fieldRef != null && dnlibExtensions.IsField(fieldRef)) {
fieldRef.WriteTo(writer);
writer.WriteComment(" // 0x" + fieldRef.MDToken.Raw.ToString("x8"));
return;
}
string s = operand as string;
if (s != null) {
writer.WriteLiteral("\"" + NRefactory.CSharp.CSharpOutputVisitor.ConvertString(s) + "\"");
} else if (operand is char) {
writer.WriteLiteral(((int)(char)operand).ToString());
} else if (operand is float) {
float val = (float)operand;
if (val == 0) {
if (1 / val == float.NegativeInfinity) {
// negative zero is a special case
writer.WriteLiteral("-");
}
writer.WriteLiteral("0.0");
} else if (float.IsInfinity(val) || float.IsNaN(val)) {
byte[] data = BitConverter.GetBytes(val);
writer.Write('(');
for (int i = 0; i < data.Length; i++) {
if (i > 0)
writer.WriteLiteral(" ");
writer.WriteLiteral(data[i].ToString("X2"));
}
writer.Write(')');
} else {
writer.WriteLiteral(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture));
}
} else if (operand is double) {
double val = (double)operand;
if (val == 0) {
if (1 / val == double.NegativeInfinity) {
// negative zero is a special case
writer.WriteLiteral("-");
}
writer.WriteLiteral("0.0");
} else if (double.IsInfinity(val) || double.IsNaN(val)) {
byte[] data = BitConverter.GetBytes(val);
writer.Write('(');
for (int i = 0; i < data.Length; i++) {
if (i > 0)
writer.WriteLiteral(" ");
writer.WriteLiteral(data[i].ToString("X2"));
}
writer.Write(')');
} else {
writer.WriteLiteral(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture));
//.........这里部分代码省略.........