本文整理汇总了C#中MethodReference类的典型用法代码示例。如果您正苦于以下问题:C# MethodReference类的具体用法?C# MethodReference怎么用?C# MethodReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodReference类属于命名空间,在下文中一共展示了MethodReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPopCount
/// <summary>
/// Get the number of values removed on the stack for this instruction.
/// </summary>
/// <param name="self">The Instruction on which the extension method can be called.</param>
/// <param name="method">The method inside which the instruction comes from (needed for StackBehaviour.Varpop).</param>
/// <param name="currentstacksize">This method returns this value when stack behaviour is StackBehaviour.PopAll.</param>
/// <returns>The number of values removed (pop) from the stack for this instruction.</returns>
public static int GetPopCount(this Instruction self, MethodReference method, int currentstacksize = 0)
{
if (self == null)
throw new ArgumentException("self");
if (method == null)
throw new ArgumentException("method");
var sbp = self.OpCode.StackBehaviourPop;
if (sbp != StackBehaviour.Varpop)
return sbp != StackBehaviour.PopAll ? StackBehaviourCache[(int)sbp] : currentstacksize;
if (self.OpCode.FlowControl == FlowControl.Return)
return method.ReturnType.FullName == "System.Void" ? 0 : 1;
var calledMethod = self.Operand as MethodReference;
// avoid allocating empty ParameterDefinitionCollection
var n = calledMethod.HasParameters ? calledMethod.Parameters.Count : 0;
if (self.OpCode.Code == Code.Newobj)
return n;
if (calledMethod.HasThis)
n++;
return n;
}
示例2: Create
public Instruction Create(OpCode opcode, MethodReference meth)
{
if (opcode.OperandType != OperandType.InlineMethod &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, meth);
}
示例3: GenericContext
public GenericContext (IGenericParameterProvider provider)
{
if (provider is TypeReference)
m_type = provider as TypeReference;
else if (provider is MethodReference) {
MethodReference meth = provider as MethodReference;
m_method = meth;
m_type = meth.DeclaringType;
}
}
示例4: LockReplacer
internal LockReplacer(SourceMethodBody sourceMethodBody) {
Contract.Requires(sourceMethodBody != null);
this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
this.sourceLocationProvider = sourceMethodBody.sourceLocationProvider;
this.numberOfReferencesToLocal = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(sourceMethodBody.numberOfReferencesToLocal != null);
this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(sourceMethodBody.numberOfAssignmentsToLocal != null);
this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion != null);
var systemThreading = new Immutable.NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
this.host.NameTable.GetNameFor("Threading"));
var systemThreadingMonitor = new Immutable.NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
var parameters = new IParameterTypeInformation[2];
this.monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
this.host.NameTable.GetNameFor("Enter"), 0, parameters);
parameters[0] = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
parameters[1] = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
this.monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);
}
示例5: GetMethodDeclaringProperty
private static PropertyDefinition GetMethodDeclaringProperty(MethodReference method)
{
if (method == null)
{
return null;
}
TypeDefinition type = method.DeclaringType.Resolve();
if (type != null)
{
foreach (PropertyDefinition property in type.Properties)
{
if ((property.GetMethod != null && property.GetMethod.HasSameSignatureWith(method)) ||
(property.SetMethod != null && property.SetMethod.HasSameSignatureWith(method)))
{
return property;
}
}
}
return null;
}
示例6: Create
public static Instruction Create (OpCode opcode, MethodReference method)
{
if (method == null)
throw new ArgumentNullException ("method");
if (opcode.OperandType != OperandType.InlineMethod &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return new Instruction (opcode, method);
}
示例7: Create
public Instruction Create(OpCode opcode, MethodReference method)
{
return Instruction.Create (opcode, method);
}
示例8: MethodRefSignatureConverter
internal MethodRefSignatureConverter(PEFileToObjectModel peFileToObjectModel, MethodReference moduleMethodRef, MemoryReader signatureMemoryReader)
: base(peFileToObjectModel, signatureMemoryReader, moduleMethodRef) {
// TODO: Check minimum required size of the signature...
byte firstByte = this.SignatureMemoryReader.ReadByte();
if (SignatureHeader.IsGeneric(firstByte)) {
this.GenericParamCount = (ushort)this.SignatureMemoryReader.ReadCompressedUInt32();
}
int paramCount = this.SignatureMemoryReader.ReadCompressedUInt32();
bool dummyPinned;
this.ReturnCustomModifiers = this.GetCustomModifiers(out dummyPinned);
byte retByte = this.SignatureMemoryReader.PeekByte(0);
if (retByte == ElementType.Void) {
this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemVoid;
this.SignatureMemoryReader.SkipBytes(1);
} else if (retByte == ElementType.TypedReference) {
this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemTypedReference;
this.SignatureMemoryReader.SkipBytes(1);
} else {
if (retByte == ElementType.ByReference) {
this.IsReturnByReference = true;
this.SignatureMemoryReader.SkipBytes(1);
}
this.ReturnTypeReference = this.GetTypeReference();
}
if (paramCount > 0) {
this.RequiredParameters = this.GetModuleParameterTypeInformations(moduleMethodRef, paramCount);
if (this.RequiredParameters.Length < paramCount)
this.VarArgParameters = this.GetModuleParameterTypeInformations(moduleMethodRef, paramCount - this.RequiredParameters.Length);
}
}
示例9: GetMethodRefSignature
internal MethodRefSignatureConverter GetMethodRefSignature(
MethodReference moduleMethodReference
) {
uint signatureBlobOffset = this.PEFileReader.MemberRefTable.GetSignature(moduleMethodReference.MemberRefRowId);
// TODO: error checking offset in range
MemoryBlock signatureMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(signatureBlobOffset);
// TODO: Error checking enough space in signature memoryBlock.
MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock);
// TODO: Check if this is really method signature there.
MethodRefSignatureConverter methodRefSigConv = new MethodRefSignatureConverter(this, moduleMethodReference, memoryReader);
return methodRefSigConv;
}
示例10: CustomAttrib
public CustomAttrib (MethodReference ctor)
{
Constructor = ctor;
}
示例11: HasSameSignatureWith
public static bool HasSameSignatureWith(this MethodReference self, MethodReference other)
{
if (!(self.GetMethodSignature() == other.GetMethodSignature()))
{
return false;
}
if (self.ReturnType.FullName != other.ReturnType.FullName)
{
if (self.ReturnType is GenericParameter && other.ReturnType is GenericParameter)
{
if ((self.ReturnType as GenericParameter).Position == (other.ReturnType as GenericParameter).Position)
{
return true;
}
}
return false;
}
return true;
}
示例12: Rewrite
/// <summary />
public override IStatement Rewrite(IForEachStatement forEachStatement)
{
ILocalDefinition foreachLocal;
var key = forEachStatement.Collection.Type.InternedKey;
ITypeReference enumeratorType;
IMethodReference getEnumerator;
IMethodReference getCurrent;
var gtir = forEachStatement.Collection.Type as IGenericTypeInstanceReference;
if (gtir != null)
{
var typeArguments = gtir.GenericArguments;
ITypeReference genericEnumeratorType = new Immutable.GenericTypeInstanceReference(this.host.PlatformType.SystemCollectionsGenericIEnumerator, typeArguments, this.host.InternFactory);
ITypeReference genericEnumerableType = new Immutable.GenericTypeInstanceReference(this.host.PlatformType.SystemCollectionsGenericIEnumerable, typeArguments, this.host.InternFactory);
enumeratorType = genericEnumeratorType;
getEnumerator = new SpecializedMethodReference()
{
CallingConvention = CallingConvention.HasThis,
ContainingType = genericEnumerableType,
InternFactory = this.host.InternFactory,
Name = this.host.NameTable.GetNameFor("GetEnumerator"),
Parameters = new List<IParameterTypeInformation>(),
Type = genericEnumeratorType,
UnspecializedVersion = new MethodReference()
{
CallingConvention = CallingConvention.HasThis,
ContainingType = this.host.PlatformType.SystemCollectionsGenericIEnumerable,
InternFactory = this.host.InternFactory,
Name = this.host.NameTable.GetNameFor("GetEnumerator"),
Parameters = new List<IParameterTypeInformation>(),
Type = this.host.PlatformType.SystemCollectionsGenericIEnumerator,
},
};
var getEnumerator2 = (IMethodReference)
IteratorHelper.First(genericEnumerableType.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("GetEnumerator"), false));
getEnumerator = getEnumerator2;
getCurrent = (IMethodReference) IteratorHelper.First(genericEnumeratorType.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("get_Current"), false));
}
else
{
enumeratorType = this.host.PlatformType.SystemCollectionsIEnumerator;
getEnumerator = new MethodReference()
{
CallingConvention = CallingConvention.HasThis,
ContainingType = enumeratorType,
InternFactory = this.host.InternFactory,
Name = this.host.NameTable.GetNameFor("GetEnumerator"),
Parameters = new List<IParameterTypeInformation>(),
Type = this.host.PlatformType.SystemCollectionsIEnumerable,
};
getCurrent = new MethodReference()
{
CallingConvention = CallingConvention.HasThis,
ContainingType = enumeratorType,
InternFactory = this.host.InternFactory,
Name = this.host.NameTable.GetNameFor("get_Current"),
Parameters = new List<IParameterTypeInformation>(),
Type = this.host.PlatformType.SystemObject,
};
}
var initializer = new MethodCall()
{
Arguments = new List<IExpression>(),
IsStaticCall = false,
IsVirtualCall = true,
MethodToCall = getEnumerator,
ThisArgument = forEachStatement.Collection,
Type = enumeratorType,
};
IStatement initialization;
if (!this.foreachLocals.TryGetValue(key, out foreachLocal))
{
foreachLocal = new LocalDefinition() { Type = enumeratorType, Name = this.host.NameTable.GetNameFor("CS$5$" + this.foreachLocals.Count) };
this.foreachLocals.Add(key, foreachLocal);
initialization = new LocalDeclarationStatement()
{
InitialValue = initializer,
LocalVariable = foreachLocal,
};
}
else
{
initialization = new ExpressionStatement()
{
Expression = new Assignment()
{
Source = initializer,
Target = new TargetExpression()
{
Definition = foreachLocal,
Instance = null,
Type = foreachLocal.Type,
},
Type = foreachLocal.Type,
},
};
//.........这里部分代码省略.........
示例13: Import
public MethodReference Import(MethodReference meth)
{
return m_importer.ImportMethodReference (meth, this);
}
示例14: Emit
public Instruction Emit(OpCode opcode, MethodReference method)
{
var instruction = Create (opcode, method);
Append (instruction);
return instruction;
}
示例15: TraverseChildren
/// <summary>
/// Generates IL for the specified create delegate instance.
/// </summary>
/// <param name="createDelegateInstance">The create delegate instance.</param>
public override void TraverseChildren(ICreateDelegateInstance createDelegateInstance)
{
IPlatformType platformType = createDelegateInstance.Type.PlatformType;
MethodReference constructor = new MethodReference(this.host, createDelegateInstance.Type, CallingConvention.Default|CallingConvention.HasThis,
platformType.SystemVoid, this.host.NameTable.Ctor, 0, platformType.SystemObject, platformType.SystemIntPtr);
if (createDelegateInstance.Instance != null) {
this.Traverse(createDelegateInstance.Instance);
if (createDelegateInstance.IsVirtualDelegate) {
this.generator.Emit(OperationCode.Dup);
this.StackSize++;
this.generator.Emit(OperationCode.Ldvirtftn, createDelegateInstance.MethodToCallViaDelegate);
this.StackSize--;
} else
this.generator.Emit(OperationCode.Ldftn, createDelegateInstance.MethodToCallViaDelegate);
this.StackSize++;
} else {
this.generator.Emit(OperationCode.Ldnull);
this.generator.Emit(OperationCode.Ldftn, createDelegateInstance.MethodToCallViaDelegate);
this.StackSize+=2;
}
this.generator.Emit(OperationCode.Newobj, constructor);
this.StackSize--;
}