public virtual bool Build(ref GenericMethodReference genericMethodRef) { bool changed = false; var methodRef = genericMethodRef.DeclaringMethod; changed |= Build(ref methodRef); var genericArguments = new TypeSignature[genericMethodRef.GenericArguments.Count]; for (int i = 0; i < genericArguments.Length; i++) { var genericArgument = genericMethodRef.GenericArguments[i]; changed |= Build(ref genericArgument); genericArguments[i] = genericArgument; } if (!changed) { return(false); } genericMethodRef = new GenericMethodReference(methodRef, genericArguments); return(true); }
public virtual void Visit(GenericMethodReference genericMethodRef) { Visit(genericMethodRef.DeclaringMethod); for (int i = 0; i < genericMethodRef.GenericArguments.Count; i++) { Visit(genericMethodRef.GenericArguments[i]); } }
internal static MethodSignature Load(Module module, int token) { switch (MetadataToken.GetType(token)) { case MetadataTokenType.Method: return(MethodReference.LoadMethodDef(module, MetadataToken.GetRID(token))); case MetadataTokenType.MemberRef: return((MethodReference)MethodReference.LoadMemberRef(module, MetadataToken.GetRID(token))); case MetadataTokenType.MethodSpec: return(GenericMethodReference.LoadMethodSpec(module, MetadataToken.GetRID(token))); default: throw new Exception(string.Format("Invalid method reference token {0}", token.ToString())); } }
public virtual bool Predicate(GenericMethodReference genericMethodRef) { if (_defaultValue != Predicate(genericMethodRef.DeclaringMethod)) { return(!_defaultValue); } for (int i = 0; i < genericMethodRef.GenericArguments.Count; i++) { if (_defaultValue != Predicate(genericMethodRef.GenericArguments[i])) { return(!_defaultValue); } } return(_defaultValue); }
internal static GenericMethodReference LoadMethodSpec(Module module, int rid) { var image = module.Image; var genericMethodRef = image.MethodSpecSignatures[rid - 1] as GenericMethodReference; if (genericMethodRef != null) { return(genericMethodRef); } MethodSpecRow row; image.GetMethodSpec(rid, out row); genericMethodRef = new GenericMethodReference(); genericMethodRef._declaringMethod = MethodReference.LoadMethodDefOrRef(module, MetadataToken.DecompressMethodDefOrRef(row.Method)); using (var accessor = image.OpenBlob(row.Instantiation)) { byte sigType = accessor.ReadByte(); // Should be equal to SignatureType.GenericInst if (sigType != Metadata.SignatureType.GenericInst) { throw new CodeModelException(string.Format(SR.AssemblyLoadError, module.Location)); } var genericArguments = TypeSignature.LoadGenericArguments(accessor, module); genericMethodRef._genericArguments = ReadOnlyList <TypeSignature> .Create(genericArguments); } module.AddSignature(ref genericMethodRef); image.MethodSpecSignatures[rid - 1] = genericMethodRef; return(genericMethodRef); }
private void LoadInstructions(IBinaryAccessor accessor, Module module, int codeSize) { long startOffset = accessor.Position; var image = module.Image; _instructions = new List <Instruction>(); while (accessor.Position < startOffset + codeSize) { OpCode opCode; byte opByte = accessor.ReadByte(); if (opByte == 0xFE) { opByte = accessor.ReadByte(); opCode = OpCodes.OpCodeArray[256 + opByte]; } else { opCode = OpCodes.OpCodeArray[opByte]; } if (opCode == null) { throw new CodeModelException(string.Format(SR.AssemblyLoadError, module.Location)); } object value; switch (opCode.OperandType) { case OperandType.InlineBrTarget: { value = accessor.ReadInt32(); } break; case OperandType.InlineField: { int token = accessor.ReadInt32(); value = FieldReference.Load(module, token); } break; case OperandType.InlineI: { value = accessor.ReadInt32(); } break; case OperandType.InlineI8: { value = accessor.ReadInt64(); } break; case OperandType.InlineMethod: { int token = accessor.ReadInt32(); value = MethodReference.Load(module, token); } break; case OperandType.InlineR: { value = accessor.ReadDouble(); } break; case OperandType.InlineSig: { int token = accessor.ReadInt32(); if (MetadataToken.GetType(token) == MetadataTokenType.Signature) { int rid = MetadataToken.GetRID(token); value = CallSite.LoadStandAloneSig(module, rid); } else { throw new CodeModelException(SR.MethodBodyBlobNotValid); } } break; case OperandType.InlineString: { // Token of a userdefined string, whose RID portion is actually an offset in the #US blob stream. uint token = accessor.ReadUInt32(); int rid = (int)(token & 0x00ffffff); value = image.GetUserString(rid); } break; case OperandType.InlineSwitch: { int count = accessor.ReadInt32(); int[] targets = new int[count]; for (int i = 0; i < count; i++) { targets[i] = accessor.ReadInt32(); } value = targets; } break; case OperandType.InlineTok: { int token = accessor.ReadInt32(); int rid = MetadataToken.GetRID(token); switch (MetadataToken.GetType(token)) { case MetadataTokenType.Method: value = MethodReference.LoadMethodDef(module, rid); break; case MetadataTokenType.MethodSpec: value = GenericMethodReference.LoadMethodSpec(module, rid); break; case MetadataTokenType.MemberRef: value = MethodReference.LoadMemberRef(module, rid); break; case MetadataTokenType.Field: value = FieldReference.LoadFieldDef(module, rid); break; case MetadataTokenType.TypeDef: value = TypeReference.LoadTypeDef(module, rid); break; case MetadataTokenType.TypeRef: value = TypeReference.LoadTypeRef(module, rid); break; case MetadataTokenType.TypeSpec: value = TypeSignature.LoadTypeSpec(module, rid); break; default: throw new CodeModelException(SR.MethodBodyBlobNotValid); } } break; case OperandType.InlineType: { int token = accessor.ReadInt32(); value = TypeSignature.Load(module, token); } break; case OperandType.InlineVar: { value = accessor.ReadInt16(); } break; case OperandType.ShortInlineBrTarget: { value = accessor.ReadSByte(); } break; case OperandType.ShortInlineI: { value = accessor.ReadByte(); } break; case OperandType.ShortInlineR: { value = accessor.ReadSingle(); } break; case OperandType.ShortInlineVar: { value = accessor.ReadByte(); } break; default: { value = null; } break; } _instructions.Add(new Instruction(opCode, value)); } }