private void PatchMethodImpl() { MethodImplTable.Record[] methodImpls = module.MethodImpl.records; MemberRefTable.Record[] memberRefs = module.MemberRef.records; MethodDefTable.Record[] methods = module.MethodDef.records; int[] typeSpecs = module.TypeSpec.records; for (int i = 0; i < methodImpls.Length; i++) { int methodDefOrMemberRef = methodImpls[i].MethodDeclaration; if ((methodDefOrMemberRef >> 24) == MemberRefTable.Index) { int typeDefOrRef = memberRefs[(methodDefOrMemberRef & 0xFFFFFF) - 1].Class; if ((typeDefOrRef >> 24) == TypeSpecTable.Index) { typeDefOrRef = ReadTypeSpec(module.GetBlob(typeSpecs[(typeDefOrRef & 0xFFFFFF) - 1])); } if ((typeDefOrRef >> 24) == TypeRefTable.Index) { if (typeDefOrRef == typeofSystemIDisposable) { int dispose = GetString("Dispose"); methods[(methodImpls[i].MethodBody & 0xFFFFFF) - 1].Name = dispose; memberRefs[(methodImpls[i].MethodDeclaration & 0xFFFFFF) - 1].Name = dispose; } else if (projectedTypeRefs[(typeDefOrRef & 0xFFFFFF) - 1]) { methods[(methodImpls[i].MethodBody & 0xFFFFFF) - 1].Flags &= (int)~MethodAttributes.MemberAccessMask; methods[(methodImpls[i].MethodBody & 0xFFFFFF) - 1].Flags |= (int)MethodAttributes.Private; methodImpls[i].MethodBody = 0; methodImpls[i].MethodDeclaration = 0; } } else if ((typeDefOrRef >> 24) == TypeDefTable.Index) { } else if ((typeDefOrRef >> 24) == TypeSpecTable.Index) { throw new NotImplementedException(); } else { throw new BadImageFormatException(); } } } }
public override CustomModifiers[] __GetGenericParameterConstraintCustomModifiers() { IGenericContext context = (this.DeclaringMethod as IGenericContext) ?? this.DeclaringType; List <CustomModifiers> list = new List <CustomModifiers>(); foreach (int i in module.GenericParamConstraint.Filter(this.MetadataToken)) { CustomModifiers mods = new CustomModifiers(); int metadataToken = module.GenericParamConstraint.records[i].Constraint; if ((metadataToken >> 24) == TypeSpecTable.Index) { int index = (metadataToken & 0xFFFFFF) - 1; mods = CustomModifiers.Read(module, module.GetBlob(module.TypeSpec.records[index]), context); } list.Add(mods); } return(list.ToArray()); }