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


C# MethodReference类代码示例

本文整理汇总了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;
		}
开发者ID:mwoelk83,项目名称:Mono.Cecil.Fluent,代码行数:32,代码来源:InstructionExtensions.cs

示例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);
        }
开发者ID:KenMacD,项目名称:deconfuser,代码行数:8,代码来源:CilWorker.cs

示例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;
			}
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:10,代码来源:GenericContext.cs

示例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);

    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:20,代码来源:LockReplacer.cs

示例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;
		}
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:22,代码来源:PropertyReferenceExtensions.cs

示例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);
		}
开发者ID:mayuki,项目名称:Inazuma,代码行数:10,代码来源:Instruction.cs

示例7: Create

 public Instruction Create(OpCode opcode, MethodReference method)
 {
     return Instruction.Create (opcode, method);
 }
开发者ID:ttRevan,项目名称:cecil,代码行数:4,代码来源:ILProcessor.cs

示例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);
   }
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:30,代码来源:PEFileToObjectModel.cs

示例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;
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:12,代码来源:PEFileToObjectModel.cs

示例10: CustomAttrib

		public CustomAttrib (MethodReference ctor)
		{
			Constructor = ctor;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:4,代码来源:CustomAttrib.cs

示例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;
		}
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:22,代码来源:MethodReferenceExtentions.cs

示例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,
                    },
                };
//.........这里部分代码省略.........
开发者ID:xornand,项目名称:cci,代码行数:101,代码来源:ForEachRemover.cs

示例13: Import

 public MethodReference Import(MethodReference meth)
 {
     return m_importer.ImportMethodReference (meth, this);
 }
开发者ID:NALSS,项目名称:Telegraph,代码行数:4,代码来源:ImportContext.cs

示例14: Emit

 public Instruction Emit(OpCode opcode, MethodReference method)
 {
     var instruction = Create (opcode, method);
     Append (instruction);
     return instruction;
 }
开发者ID:peterwald,项目名称:cecil,代码行数:6,代码来源:ILProcessor.cs

示例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--;
 }
开发者ID:riverar,项目名称:devtools,代码行数:27,代码来源:Visitor.cs


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