本文整理汇总了C#中System.Reflection.Emit.OpCode.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# OpCode.Equals方法的具体用法?C# OpCode.Equals怎么用?C# OpCode.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.OpCode
的用法示例。
在下文中一共展示了OpCode.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
//
//
// Token resolution calls
//
//
public override void Emit(OpCode opcode, MethodInfo meth) {
if (meth == null)
throw new ArgumentNullException("meth");
int stackchange = 0;
int tempVal = 0;
DynamicMethod dynMeth = DynamicMethod.AsDynamicMethod(meth);
if (dynMeth == null) {
if (!(meth is RuntimeMethodInfo))
throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth");
if (meth.DeclaringType != null && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray))
tempVal = m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle);
else
tempVal = m_scope.GetTokenFor(meth.MethodHandle);
}
else {
// rule out not allowed operations on DynamicMethods
if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn)) {
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
}
tempVal = m_scope.GetTokenFor(dynMeth);
}
EnsureCapacity(7);
InternalEmit(opcode);
if (opcode.m_push == StackBehaviour.Varpush
&& meth.ReturnType != typeof(void)) {
stackchange++;
}
if (opcode.m_pop == StackBehaviour.Varpop) {
stackchange -= meth.GetParametersNoCopy().Length;
}
// Pop the "this" parameter if the method is non-static,
// and the instruction is not newobj/ldtoken/ldftn.
if (!meth.IsStatic &&
!(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn))) {
stackchange--;
}
UpdateStackSize(opcode, stackchange);
m_length=PutInteger4(tempVal, m_length, m_ILStream);
}
示例2: Emit
public virtual void Emit(OpCode opcode, ConstructorInfo con) {
int stackchange = 0;
int tk = GetMethodToken(con, null);
EnsureCapacity(7);
InternalEmit(opcode);
// Make a conservative estimate by assuming a return type and no
// this parameter.
if (opcode.m_push == StackBehaviour.Varpush)
{
// Instruction must be one of call or callvirt.
BCLDebug.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt),
"Unexpected opcode encountered for StackBehaviour of VarPush.");
stackchange++;
}
if (opcode.m_pop == StackBehaviour.Varpop)
{
// Instruction must be one of call, callvirt or newobj.
BCLDebug.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt) ||
opcode.Equals(OpCodes.Newobj),
"Unexpected opcode encountered for StackBehaviour of VarPop.");
if (con.GetParameterTypes() != null)
stackchange -= con.GetParameterTypes().Length;
}
UpdateStackSize(opcode, stackchange);
RecordTokenFixup();
m_length=PutInteger4(tk, m_length, m_ILStream);
}
示例3: Emit
public virtual void Emit(OpCode opcode, ConstructorInfo con)
{
if (con == null)
throw new ArgumentNullException("con");
Contract.EndContractBlock();
int stackchange = 0;
// Constructors cannot be generic so the value of UseMethodDef doesn't matter.
int tk = GetMethodToken(con, null, true);
EnsureCapacity(7);
InternalEmit(opcode);
// Make a conservative estimate by assuming a return type and no
// this parameter.
if (opcode.StackBehaviourPush == StackBehaviour.Varpush)
{
// Instruction must be one of call or callvirt.
Contract.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt),
"Unexpected opcode encountered for StackBehaviour of VarPush.");
stackchange++;
}
if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
{
// Instruction must be one of call, callvirt or newobj.
Contract.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt) ||
opcode.Equals(OpCodes.Newobj),
"Unexpected opcode encountered for StackBehaviour of VarPop.");
Type[] parameters = con.GetParameterTypes();
if (parameters != null)
stackchange -= parameters.Length;
}
UpdateStackSize(opcode, stackchange);
RecordTokenFixup();
PutInteger4(tk);
}
示例4: EmitCall
[System.Security.SecuritySafeCritical] // auto-generated
public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
{
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");
if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)))
throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), "opcode");
Contract.EndContractBlock();
int stackchange = 0;
int tk = GetMethodToken(methodInfo, optionalParameterTypes, false);
EnsureCapacity(7);
InternalEmit(opcode);
// Push the return value if there is one.
if (methodInfo.ReturnType != typeof(void))
stackchange++;
// Pop the parameters.
Type[] parameters = methodInfo.GetParameterTypes();
if (parameters != null)
stackchange -= parameters.Length;
// Pop the this parameter if the method is non-static and the
// instruction is not newobj.
if (!(methodInfo is SymbolMethod) && methodInfo.IsStatic == false && !(opcode.Equals(OpCodes.Newobj)))
stackchange--;
// Pop the optional parameters off the stack.
if (optionalParameterTypes != null)
stackchange -= optionalParameterTypes.Length;
UpdateStackSize(opcode, stackchange);
RecordTokenFixup();
PutInteger4(tk);
}
示例5: EmitUnconditionalBranch
/// <summary>
/// Unconditional branch opcodes (OpCode.Br, OpCode.Br_S) can lead to unverifiable code in the following cases:
///
/// # DEAD CODE CASE
/// ldc_i4 1 # Stack depth == 1
/// br Label2
/// Label1:
/// nop # Dead code, so IL rules assume stack depth == 0. This causes a verification error,
/// # since next instruction has depth == 1
/// Label2:
/// pop # Stack depth == 1
/// ret
///
/// # LATE BRANCH CASE
/// ldc_i4 1 # Stack depth == 1
/// br Label2
/// Label1:
/// nop # Not dead code, but since branch comes from below, IL rules assume stack depth = 0.
/// # This causes a verification error, since next instruction has depth == 1
/// Label2:
/// pop # Stack depth == 1
/// ret
/// Label3:
/// br Label1 # Stack depth == 1
///
/// This method works around the above limitations by using Brtrue or Brfalse in the following way:
///
/// ldc_i4 1 # Since this test is always true, this is a way of creating a path to the code that
/// brtrue Label # follows the brtrue instruction.
///
/// ldc_i4 1 # Since this test is always false, this is a way of creating a path to the code that
/// brfalse Label # starts at Label.
///
/// 1. If opcode == Brtrue or Brtrue_S, then 1 will be pushed and brtrue instruction will be generated.
/// 2. If opcode == Brfalse or Brfalse_S, then 1 will be pushed and brfalse instruction will be generated.
/// 3. If opcode == Br or Br_S, then a br instruction will be generated.
/// </summary>
public void EmitUnconditionalBranch(OpCode opcode, Label lblTarget)
{
if (!opcode.Equals(OpCodes.Br) && !opcode.Equals(OpCodes.Br_S))
{
Debug.Assert(opcode.Equals(OpCodes.Brtrue) || opcode.Equals(OpCodes.Brtrue_S) ||
opcode.Equals(OpCodes.Brfalse) || opcode.Equals(OpCodes.Brfalse_S));
Emit(OpCodes.Ldc_I4_1);
}
#if DEBUG
if (XmlILTrace.IsEnabled)
this.writerDump.WriteLine(" {0, -10} Label {1}", opcode.Name, this.symbols[lblTarget]);
#endif
_ilgen.Emit(opcode, lblTarget);
if (_lastSourceInfo != null && (opcode.Equals(OpCodes.Br) || opcode.Equals(OpCodes.Br_S)))
{
// Emit a "no source" sequence point, otherwise the following label will be preceded
// with a dead Nop operation, which may lead to unverifiable code (SQLBUDT 423393).
// We are guaranteed not to emit adjacent sequence points because Br or Br_S
// instruction precedes this sequence point, and a Nop instruction precedes other
// sequence points.
MarkSequencePoint(SourceLineInfo.NoSource);
}
}
示例6: Emit
public void Emit(OpCode opcode, Label lblVal)
{
Debug.Assert(!opcode.Equals(OpCodes.Br) && !opcode.Equals(OpCodes.Br_S), "Use EmitUnconditionalBranch and be careful not to emit unverifiable code.");
#if DEBUG
if (XmlILTrace.IsEnabled)
this.writerDump.WriteLine(" {0, -10} Label {1}", opcode.Name, this.symbols[lblVal]);
#endif
_ilgen.Emit(opcode, lblVal);
}
示例7: Emit
[System.Security.SecuritySafeCritical] // auto-generated
public override void Emit(OpCode opcode, MethodInfo meth)
{
if (meth == null)
throw new ArgumentNullException(nameof(meth));
Contract.EndContractBlock();
int stackchange = 0;
int token = 0;
DynamicMethod dynMeth = meth as DynamicMethod;
if (dynMeth == null)
{
RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo;
if (rtMeth == null)
throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(meth));
RuntimeType declaringType = rtMeth.GetRuntimeType();
if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray))
token = GetTokenFor(rtMeth, declaringType);
else
token = GetTokenFor(rtMeth);
}
else
{
// rule out not allowed operations on DynamicMethods
if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn))
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
}
token = GetTokenFor(dynMeth);
}
EnsureCapacity(7);
InternalEmit(opcode);
if (opcode.StackBehaviourPush == StackBehaviour.Varpush
&& meth.ReturnType != typeof(void))
{
stackchange++;
}
if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
{
stackchange -= meth.GetParametersNoCopy().Length;
}
// Pop the "this" parameter if the method is non-static,
// and the instruction is not newobj/ldtoken/ldftn.
if (!meth.IsStatic &&
!(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn)))
{
stackchange--;
}
UpdateStackSize(opcode, stackchange);
PutInteger4(token);
}
示例8: EmitCall
[System.Security.SecuritySafeCritical] // auto-generated
public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
{
if (methodInfo == null)
throw new ArgumentNullException(nameof(methodInfo));
if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)))
throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), nameof(opcode));
if (methodInfo.ContainsGenericParameters)
throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo));
if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.ContainsGenericParameters)
throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo));
Contract.EndContractBlock();
int tk;
int stackchange = 0;
tk = GetMemberRefToken(methodInfo, optionalParameterTypes);
EnsureCapacity(7);
InternalEmit(opcode);
// Push the return value if there is one.
if (methodInfo.ReturnType != typeof(void))
stackchange++;
// Pop the parameters.
stackchange -= methodInfo.GetParameterTypes().Length;
// Pop the this parameter if the method is non-static and the
// instruction is not newobj.
if (!(methodInfo is SymbolMethod) && methodInfo.IsStatic == false && !(opcode.Equals(OpCodes.Newobj)))
stackchange--;
// Pop the optional parameters off the stack.
if (optionalParameterTypes != null)
stackchange -= optionalParameterTypes.Length;
UpdateStackSize(opcode, stackchange);
PutInteger4(tk);
}
示例9: EmitUnconditionalBranch
/// <summary>
/// Unconditional branch opcodes (OpCode.Br, OpCode.Br_S) can lead to unverifiable code in the following cases:
///
/// # DEAD CODE CASE
/// ldc_i4 1 # Stack depth == 1
/// br Label2
/// Label1:
/// nop # Dead code, so IL rules assume stack depth == 0. This causes a verification error,
/// # since next instruction has depth == 1
/// Label2:
/// pop # Stack depth == 1
/// ret
///
/// # LATE BRANCH CASE
/// ldc_i4 1 # Stack depth == 1
/// br Label2
/// Label1:
/// nop # Not dead code, but since branch comes from below, IL rules assume stack depth = 0.
/// # This causes a verification error, since next instruction has depth == 1
/// Label2:
/// pop # Stack depth == 1
/// ret
/// Label3:
/// br Label1 # Stack depth == 1
///
/// This method works around the above limitations by using Brtrue or Brfalse in the following way:
///
/// ldc_i4 1 # Since this test is always true, this is a way of creating a path to the code that
/// brtrue Label # follows the brtrue instruction.
///
/// ldc_i4 1 # Since this test is always false, this is a way of creating a path to the code that
/// brfalse Label # starts at Label.
///
/// 1. If opcode == Brtrue or Brtrue_S, then 1 will be pushed and brtrue instruction will be generated.
/// 2. If opcode == Brfalse or Brfalse_S, then 1 will be pushed and brfalse instruction will be generated.
/// 3. If opcode == Br or Br_S, then a br instruction will be generated.
/// </summary>
public void EmitUnconditionalBranch(OpCode opcode, Label lblTarget) {
if (!opcode.Equals(OpCodes.Br) && !opcode.Equals(OpCodes.Br_S)) {
Debug.Assert(opcode.Equals(OpCodes.Brtrue) || opcode.Equals(OpCodes.Brtrue_S) ||
opcode.Equals(OpCodes.Brfalse) || opcode.Equals(OpCodes.Brfalse_S));
Emit(OpCodes.Ldc_I4_1);
}
#if DEBUG
if (XmlILTrace.IsEnabled)
this.writerDump.WriteLine(" {0, -10} Label {1}", opcode.Name, this.symbols[lblTarget]);
#endif
this.ilgen.Emit(opcode, lblTarget);
}
示例10: Emit
/// <include file='doc\ILGenerator.uex' path='docs/doc[@for="ILGenerator.Emit7"]/*' />
public virtual void Emit(OpCode opcode, ConstructorInfo con) {
int stackchange = 0;
ModuleBuilder modBuilder = (ModuleBuilder) m_methodBuilder.GetModule();
int tempVal = modBuilder.GetConstructorToken( con ).Token;
EnsureCapacity(7);
internalEmit(opcode);
// Make a conservative estimate by assuming a return type and no
// this parameter.
if (opcode.m_push == StackBehaviour.Varpush)
{
// Instruction must be one of call or callvirt.
BCLDebug.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt),
"Unexpected opcode encountered for StackBehaviour of VarPush.");
stackchange++;
}
if (opcode.m_pop == StackBehaviour.Varpop)
{
// Instruction must be one of call, callvirt or newobj.
BCLDebug.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt) ||
opcode.Equals(OpCodes.Newobj),
"Unexpected opcode encountered for StackBehaviour of VarPop.");
if (con is RuntimeConstructorInfo)
{
if (con.GetParameters() != null)
stackchange -= con.GetParameters().Length;
}
else if (con is ConstructorBuilder)
{
if (((ConstructorBuilder)con).m_methodBuilder.GetParameterTypes() != null)
stackchange -= ((ConstructorBuilder)con).m_methodBuilder.GetParameterTypes().Length;
}
else
BCLDebug.Assert(false, "Unexpected type of ConstructorInfo encountered.");
}
UpdateStackSize(opcode, stackchange);
RecordTokenFixup();
m_length=PutInteger4(tempVal, m_length, m_ILStream);
}
示例11: EmitCall
//***********************************************
//
// Emit call instructions
//
//***********************************************
/// <include file='doc\ILGenerator.uex' path='docs/doc[@for="ILGenerator.EmitCall"]/*' />
public void EmitCall(
OpCode opcode, // call instruction, such as call, callvirt, calli
MethodInfo methodInfo, // target method
Type[] optionalParameterTypes) // optional parameters if methodInfo is a vararg method
{
int tk;
int stackchange = 0;
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");
ModuleBuilder modBuilder = (ModuleBuilder) m_methodBuilder.GetModule();
tk = GetVarArgMemberRefToken(methodInfo, optionalParameterTypes);
EnsureCapacity(7);
internalEmit(opcode);
// The opcode must be one of call, callvirt, or newobj.
BCLDebug.Assert(opcode.Equals(OpCodes.Call) ||
opcode.Equals(OpCodes.Callvirt) ||
opcode.Equals(OpCodes.Newobj),
"Unexpected opcode passed to EmitCall.");
// Push the return value if there is one.
if (methodInfo.ReturnType != typeof(void))
stackchange++;
// Pop the parameters.
if (methodInfo is MethodBuilder)
{
if (((MethodBuilder)methodInfo).GetParameterTypes() != null)
stackchange -= ((MethodBuilder)methodInfo).GetParameterTypes().Length;
}
else if (methodInfo is SymbolMethod)
{
if (((SymbolMethod)methodInfo).GetParameterTypes() != null)
stackchange -= ((SymbolMethod)methodInfo).GetParameterTypes().Length;
}
else if (methodInfo.GetParameters() != null)
stackchange -= methodInfo.GetParameters().Length;
// Pop the this parameter if the method is non-static and the
// instruction is not newobj.
if (!(methodInfo is SymbolMethod) && methodInfo.IsStatic == false && !(opcode.Equals(OpCodes.Newobj)))
stackchange--;
// Pop the optional parameters off the stack.
if (optionalParameterTypes != null)
stackchange -= optionalParameterTypes.Length;
UpdateStackSize(opcode, stackchange);
RecordTokenFixup();
m_length=PutInteger4(tk, m_length, m_ILStream);
}
示例12: EmitCalli
//***********************************************
//
// Emit calli instructions taking a unmanaged calling convention
// System.Runtime.InteropServices such as STDCALL, CDECL,..
//
//***********************************************
/// <include file='doc\ILGenerator.uex' path='docs/doc[@for="ILGenerator.EmitCalli1"]/*' />
public void EmitCalli(
OpCode opcode,
CallingConvention unmanagedCallConv,
Type returnType,
Type[] parameterTypes)
{
int stackchange = 0;
int cParams = 0;
int i;
SignatureHelper sig;
ModuleBuilder modBuilder = (ModuleBuilder) m_methodBuilder.GetModule();
// The opcode passed in must be the calli instruction.
BCLDebug.Assert(opcode.Equals(OpCodes.Calli),
"Unexpected opcode passed to EmitCalli.");
if (parameterTypes != null)
{
cParams = parameterTypes.Length;
}
sig = SignatureHelper.GetMethodSigHelper(
m_methodBuilder.GetModule(),
unmanagedCallConv,
returnType);
if (parameterTypes != null)
{
for (i = 0; i < cParams; i++)
{
sig.AddArgument(parameterTypes[i]);
}
}
// If there is a non-void return type, push one.
if (returnType != typeof(void))
stackchange++;
// Pop off arguments if any.
if (parameterTypes != null)
stackchange -= cParams;
// Pop the native function pointer.
stackchange--;
UpdateStackSize(opcode, stackchange);
EnsureCapacity(7);
Emit(OpCodes.Calli);
RecordTokenFixup();
m_length=PutInteger4(modBuilder.GetSignatureToken(sig).Token, m_length, m_ILStream);
}
示例13: GetGroupOfOpCode
public static OpCodeGroup GetGroupOfOpCode(OpCode opCode)
{
OpCodeGroup result = OpCodeGroup.Parameterless;
if (FieldParameter.Contains(opCode))
{
result = OpCodeGroup.FieldParameter;
}
else if (MethodParameter.Contains(opCode))
{
result = OpCodeGroup.MethodParameter;
}
else if (StringParameter.Contains(opCode))
{
result = OpCodeGroup.StringParameter;
}
else if (TypeParameter.Contains(opCode))
{
result = OpCodeGroup.TypeParameter;
}
else if (SbyteLocationParameter.Contains(opCode))
{
result = OpCodeGroup.SbyteLocationParameter;
}
else if (IntLocationParameter.Contains(opCode))
{
result = OpCodeGroup.IntLocationParameter;
}
else if (ByteParameter.Contains(opCode))
{
result = OpCodeGroup.ByteParameter;
}
else if (UshortParameter.Contains(opCode))
{
result = OpCodeGroup.UshortParameter;
}
else if (SbyteParameter.Contains(opCode))
{
result = OpCodeGroup.SbyteParameter;
}
else if (IntParameter.Contains(opCode))
{
result = OpCodeGroup.IntParameter;
}
else if (LongParameter.Contains(opCode))
{
result = OpCodeGroup.LongParameter;
}
else if (FloatParameter.Contains(opCode))
{
result = OpCodeGroup.FloatParameter;
}
else if (DoubleParameter.Contains(opCode))
{
result = OpCodeGroup.DoubleParameter;
}
else if (ByteArgumentParameter.Contains(opCode))
{
result = OpCodeGroup.ByteArgumentParameter;
}
else if (UshortArgumentParameter.Contains(opCode))
{
result = OpCodeGroup.UshortArgumentParameter;
}
else if (ByteVariableParameter.Contains(opCode))
{
result = OpCodeGroup.ByteVariableParameter;
}
else if (UshortVariableParameter.Contains(opCode))
{
result = OpCodeGroup.UshortVariableParameter;
}
else if (opCode.Equals(OpCodes.Calli))
{
result = OpCodeGroup.Calli;
}
else if (opCode.Equals(OpCodes.Switch))
{
result = OpCodeGroup.Switch;
}
else if (opCode.Equals(OpCodes.Ldtoken))
{
result = OpCodeGroup.Ldtoken;
}
return result;
}
示例14: EmitDoubleToIntegerTruncatedConversion
internal static void EmitDoubleToIntegerTruncatedConversion(ILGenerator il, OpCode opConversion) {
il.Emit(OpCodes.Call, CompilerGlobals.doubleToInt64);
if (!opConversion.Equals(OpCodes.Conv_I8))
il.Emit(opConversion);
}
示例15: EmitDecimalToIntegerTruncatedConversion
internal static void EmitDecimalToIntegerTruncatedConversion(ILGenerator il, OpCode opConversion) {
il.Emit(OpCodes.Call, CompilerGlobals.uncheckedDecimalToInt64Method);
if (!opConversion.Equals(OpCodes.Conv_I8))
il.Emit(opConversion);
}