• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MethodReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MethodReference的典型用法代码示例。如果您正苦于以下问题:C# MethodReference类的具体用法?C# MethodReference怎么用?C# MethodReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodReference类属于命名空间,在下文中一共展示了MethodReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetModuleMemberReferenceAtRowWorker

    //^ invariant this.PEFileReader.MethodSpecTable.NumberOfRows >= 1 ==> this.MethodSpecHashtable != null;

    internal MemberReference/*?*/ GetModuleMemberReferenceAtRowWorker(
      MetadataObject owningObject,
      uint memberRefRowId
    ) {
      if (memberRefRowId == 0 || memberRefRowId > this.PEFileReader.MemberRefTable.NumberOfRows) {
        return null;
      }
      if (this.ModuleMemberReferenceArray[memberRefRowId] == null) {
        MemberRefRow memberRefRow = this.PEFileReader.MemberRefTable[memberRefRowId];
        uint classTokenType = memberRefRow.Class & TokenTypeIds.TokenTypeMask;
        uint classRowId = memberRefRow.Class & TokenTypeIds.RIDMask;
        IModuleTypeReference/*?*/ parentTypeReference = null;
        switch (classTokenType) {
          case TokenTypeIds.TypeDef:
            parentTypeReference = this.GetTypeDefinitionAtRowWorker(classRowId);
            break;
          case TokenTypeIds.TypeRef:
            parentTypeReference = this.GetTypeRefReferenceAtRowWorker(classRowId);
            break;
          case TokenTypeIds.TypeSpec:
            parentTypeReference = this.GetTypeSpecReferenceAtRow(owningObject, classRowId).UnderlyingModuleTypeReference;
            break;
          case TokenTypeIds.MethodDef: {
              MethodDefinition/*?*/ methodDef = this.GetMethodDefAtRow(classRowId);
              if (methodDef == null) {
                //  Error...
                return null;
              }
              parentTypeReference = methodDef.OwningModuleType;
              break;
            }
          case TokenTypeIds.ModuleRef: {
              ModuleReference/*?*/ modRef = this.GetModuleReferenceAt(classRowId);
              if (modRef == null) {
                //  MDError
                return null;
              }
              Module/*?*/ module = this.ResolveModuleRefReference(modRef);
              if (module == null) {
                //TODO: MDError...
                return null;
              }
              PEFileToObjectModel modulePEFileToObjectModel = module.PEFileToObjectModel;
              parentTypeReference = modulePEFileToObjectModel._Module_;
              break;
            }
          default: {
              //  MDError...
              return null;
            }
        }
        if (parentTypeReference == null) {
          //  Error...
          return null;
        }
        MemberReference retModuleMemberReference;
        IName name = this.GetNameFromOffset(memberRefRow.Name);
        byte firstByte = this.PEFileReader.BlobStream.GetByteAt(memberRefRow.Signature, 0);
        IModuleGenericTypeInstance/*?*/ genericTypeInstance = parentTypeReference as IModuleGenericTypeInstance;
        IModuleSpecializedNestedTypeReference/*?*/ specializedNestedTypeReference = parentTypeReference as IModuleSpecializedNestedTypeReference;
        if (SignatureHeader.IsFieldSignature(firstByte)) {
          if (genericTypeInstance != null) {
            //The same memberRef token can be shared by distinct instance references, therefore recompute every time.
            return new GenericInstanceFieldReference(this, memberRefRowId, genericTypeInstance, name);
          } else if (specializedNestedTypeReference != null) {
            //The same memberRef token can be shared by distinct instance references, therefore recompute every time.
            return new SpecializedNestedTypeFieldReference(this, memberRefRowId, parentTypeReference, specializedNestedTypeReference, name);
          } else {
            retModuleMemberReference = new FieldReference(this, memberRefRowId, parentTypeReference, name);
          }
        } else if (SignatureHeader.IsMethodSignature(firstByte)) {
          if (genericTypeInstance != null) {
            //The same memberRef token can be shared by distinct instance references, therefore recompute every time.
            return new GenericInstanceMethodReference(this, memberRefRowId, genericTypeInstance, name, firstByte);
          } else if (specializedNestedTypeReference != null) {
            //The same memberRef token can be shared by distinct instance references, therefore recompute every time.
            return new SpecializedNestedTypeMethodReference(this, memberRefRowId, parentTypeReference, specializedNestedTypeReference, name, firstByte);
          } else {
            retModuleMemberReference = new MethodReference(this, memberRefRowId, parentTypeReference, name, firstByte);
          }
        } else {
          //  MD Error
          return null;
        }
        this.ModuleMemberReferenceArray[memberRefRowId] = retModuleMemberReference;
      }
      MemberReference/*?*/ ret = this.ModuleMemberReferenceArray[memberRefRowId];
      return ret;
    }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:91,代码来源:PEFileToObjectModel.cs


示例17: MethodRefSignatureConverter

 //^ [NotDelayed]
 internal MethodRefSignatureConverter(
   PEFileToObjectModel peFileToObjectModel,
   MethodReference moduleMethodRef,
   MemoryReader signatureMemoryReader
 )
   : base(peFileToObjectModel, signatureMemoryReader, moduleMethodRef) {
   //^ this.ReturnCustomModifiers = TypeCache.EmptyCustomModifierArray;
   this.RequiredParameters = TypeCache.EmptyParameterInfoArray;
   this.VarArgParameters = TypeCache.EmptyParameterInfoArray;
   //^ base;
   //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary.
   //  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.SystemVoid;
     this.SignatureMemoryReader.SkipBytes(1);
   } else if (retByte == ElementType.TypedReference) {
     this.ReturnTypeReference = peFileToObjectModel.SystemTypedReference;
     this.SignatureMemoryReader.SkipBytes(1);
   } else {
     if (retByte == ElementType.ByReference) {
       this.IsReturnByReference = true;
       this.SignatureMemoryReader.SkipBytes(1);
     }
     this.ReturnTypeReference = this.GetTypeReference();
   }
   if (paramCount > 0) {
     IModuleParameterTypeInformation[] reqModuleParamArr = this.GetModuleParameterTypeInformations(moduleMethodRef, paramCount);
     if (reqModuleParamArr.Length > 0)
       this.RequiredParameters = new EnumerableArrayWrapper<IModuleParameterTypeInformation, IParameterTypeInformation>(reqModuleParamArr, Dummy.ParameterTypeInformation);
     IModuleParameterTypeInformation[] varArgModuleParamArr = this.GetModuleParameterTypeInformations(moduleMethodRef, paramCount - reqModuleParamArr.Length);
     if (varArgModuleParamArr.Length > 0)
       this.VarArgParameters = new EnumerableArrayWrapper<IModuleParameterTypeInformation, IParameterTypeInformation>(varArgModuleParamArr, Dummy.ParameterTypeInformation);
   }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:43,代码来源:PEFileToObjectModel.cs


示例18: GetMethodDeclaringEvent

		private static EventDefinition GetMethodDeclaringEvent(MethodReference method)
		{
			if (method == null)
			{
				return null;
			}

			TypeDefinition type = method.DeclaringType.Resolve();
			if (type != null)
			{
				foreach (EventDefinition @event in type.Events)
				{
					if ((@event.AddMethod != null && @event.AddMethod.HasSameSignatureWith(method)) ||
						(@event.RemoveMethod != null && @event.RemoveMethod.HasSameSignatureWith(method)))
					{
						return @event;
					}
				}
			}

			return null;
		}
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:22,代码来源:EventDefinitionExtensions.cs


示例19: GetModuleMemberReferenceAtRowWorker

    //^ invariant this.PEFileReader.MethodSpecTable.NumberOfRows >= 1 ==> this.MethodSpecHashtable != null;

    internal ITypeMemberReference/*?*/ GetModuleMemberReferenceAtRowWorker(
      MetadataObject owningObject,
      uint memberRefRowId
    ) {
      if (memberRefRowId == 0 || memberRefRowId > this.PEFileReader.MemberRefTable.NumberOfRows) {
        return null;
      }
      if (this.ModuleMemberReferenceArray[memberRefRowId] == null) {
        MemberRefRow memberRefRow = this.PEFileReader.MemberRefTable[memberRefRowId];
        uint classTokenType = memberRefRow.Class & TokenTypeIds.TokenTypeMask;
        uint classRowId = memberRefRow.Class & TokenTypeIds.RIDMask;
        ITypeReference/*?*/ parentTypeReference = null;
        switch (classTokenType) {
          case TokenTypeIds.TypeDef:
            parentTypeReference = this.GetTypeDefinitionAtRow(classRowId);
            break;
          case TokenTypeIds.TypeRef:
            parentTypeReference = this.GetTypeRefReferenceAtRow(classRowId);
            break;
          case TokenTypeIds.TypeSpec:
            parentTypeReference = this.GetTypeSpecReferenceAtRow(owningObject, classRowId).UnderlyingModuleTypeReference;
            break;
          case TokenTypeIds.MethodDef: {
              var/*?*/ methodDef = this.GetMethodDefAtRow(classRowId);
              if (methodDef == null) {
                //  Error...
                return null;
              }
              parentTypeReference = methodDef.ContainingType;
              break;
            }
          case TokenTypeIds.ModuleRef: {
              ModuleReference/*?*/ modRef = this.GetModuleReferenceAt(classRowId);
              if (modRef == null) {
                //  MDError
                return null;
              }
              var module = this.ResolveModuleRefReference(modRef) as Module;
              if (module == null) {
                //TODO: MDError...
                return null;
              }
              PEFileToObjectModel modulePEFileToObjectModel = module.PEFileToObjectModel;
              parentTypeReference = modulePEFileToObjectModel._Module_;
              break;
            }
          default: {
              //  MDError...
              return null;
            }
        }
        if (parentTypeReference == null) {
          //  Error...
          return null;
        }
        MemberReference retModuleMemberReference;
        IName name = this.GetNameFromOffset(memberRefRow.Name);
        byte firstByte = this.PEFileReader.BlobStream.GetByteAt(memberRefRow.Signature, 0);
        var genericTypeInstance = parentTypeReference as IGenericTypeInstanceReference;
        var specializedNestedTypeReference = parentTypeReference as ISpecializedNestedTypeReference;
        if (SignatureHeader.IsFieldSignature(firstByte)) {
          if (genericTypeInstance != null || specializedNestedTypeReference != null) {
            //The same memberRef token can be shared by distinct instance references, therefore special caching is required
            FieldReference unspecializedFieldReference = this.UnspecializedMemberReferenceArray[memberRefRowId] as FieldReference;
            if (unspecializedFieldReference == null) {
              unspecializedFieldReference = new FieldReference(this, memberRefRowId, TypeCache.Unspecialize(parentTypeReference), name);
              this.UnspecializedMemberReferenceArray[memberRefRowId] = unspecializedFieldReference;
            }
            uint key1 = parentTypeReference.InternedKey;
            uint key2 = unspecializedFieldReference.InternedKey;
            var specializedField = this.SpecializedFieldHashtable.Find(key1, key2);
            if (specializedField == null) {
              specializedField = new SpecializedFieldReference(parentTypeReference, unspecializedFieldReference, this.InternFactory);
              this.SpecializedFieldHashtable.Add(key1, key2, specializedField);
            }
            return specializedField;
          } else {
            retModuleMemberReference = new FieldReference(this, memberRefRowId, parentTypeReference, name);
          }
        } else if (SignatureHeader.IsMethodSignature(firstByte)) {
          if (genericTypeInstance != null || specializedNestedTypeReference != null) {
            //The same memberRef token can be shared by distinct instance references, therefore special caching is required
            MethodReference unspecializedMethodReference = this.UnspecializedMemberReferenceArray[memberRefRowId] as MethodReference;
            if (unspecializedMethodReference == null) {
              unspecializedMethodReference = new MethodReference(this, memberRefRowId, TypeCache.Unspecialize(parentTypeReference), name, firstByte);
              this.UnspecializedMemberReferenceArray[memberRefRowId] = unspecializedMethodReference;
            }
            uint key1 = parentTypeReference.InternedKey;
            uint key2 = unspecializedMethodReference.InternedKey;
            var specializedMethod = this.SpecializedMethodHashtable.Find(key1, key2);
            if (specializedMethod == null) {
              specializedMethod = new SpecializedMethodReference(parentTypeReference, unspecializedMethodReference, this.InternFactory);
              this.SpecializedMethodHashtable.Add(key1, key2, specializedMethod);
            }
            return specializedMethod;
          } else {
            retModuleMemberReference = new MethodReference(this, memberRefRowId, parentTypeReference, name, firstByte);
          }
//.........这里部分代码省略.........
开发者ID:Biegal,项目名称:Afterthought,代码行数:101,代码来源:PEFileToObjectModel.cs


示例20: ResolveParameterType

		public static TypeReference ResolveParameterType(this ParameterReference param, MethodReference method)
		{
			TypeReference parameterType = param.ParameterType;
			GenericParameter genericParameter = parameterType as GenericParameter;
			//if (parameterType is GenericInstanceType)
			//{
			//    return ResolveParameterGenericInstanceType(parameterType as GenericInstanceType);
			//}
			bool isByRef = false;
			bool isArray = false;

			if (parameterType.IsByReference)
			{
				genericParameter = parameterType.GetElementType() as GenericParameter;
				isByRef = true;
			}
			if (parameterType.IsArray)
			{
				genericParameter = parameterType.GetElementType() as GenericParameter;
				isArray = true;
			}

			if (genericParameter == null)
			{
				return parameterType;
			}
			int index = genericParameter.Position;
			if (genericParameter.Owner is MethodReference && method.IsGenericInstance)
			{
				GenericInstanceMethod generic = method as GenericInstanceMethod;
				if (index >= 0 && index < generic.GenericArguments.Count)
				{
					parameterType = generic.GenericArguments[index];
					if (generic.PostionToArgument.ContainsKey(index))
					{
						parameterType = generic.PostionToArgument[index];
					}
				}
			}
			else if (genericParameter.Owner is TypeReference && method.DeclaringType.IsGenericInstance)
			{
				GenericInstanceType generic = method.DeclaringType as GenericInstanceType;
				if (index >= 0 && index < generic.GenericArguments.Count)
				{
					parameterType = generic.GenericArguments[index];
					if (generic.PostionToArgument.ContainsKey(index))
					{
						parameterType = generic.PostionToArgument[index];
					}
				}
			}
			if (isByRef)
			{
				return new ByReferenceType(parameterType);
			}
			if (isArray)
			{
				return new ArrayType(parameterType);
			}
			return parameterType;
		}
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:61,代码来源:ParameterReferenceExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MethodReturnEventArgs类代码示例发布时间:2022-05-24
下一篇:
C# MethodKind类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap