예제 #1
0
 public void EmitCall(OpCode opc, MethodInfo method, Type[] optionalParameterTypes)
 {
     if (optionalParameterTypes == null || optionalParameterTypes.Length == 0)
     {
         Emit(opc, method);
     }
     else
     {
         Emit(opc);
         UpdateStack(opc, method.HasThis, method.ReturnType, method.ParameterCount + optionalParameterTypes.Length);
         ByteBuffer sig = new ByteBuffer(16);
         method.MethodSignature.WriteMethodRefSig(moduleBuilder, sig, optionalParameterTypes);
         MemberRefTable.Record record = new MemberRefTable.Record();
         if (method.Module == moduleBuilder)
         {
             record.Class = method.MetadataToken;
         }
         else
         {
             record.Class = moduleBuilder.GetTypeTokenForMemberRef(method.DeclaringType ?? method.Module.GetModuleType());
         }
         record.Name      = moduleBuilder.Strings.Add(method.Name);
         record.Signature = moduleBuilder.Blobs.Add(sig);
         code.Write(0x0A000000 | moduleBuilder.MemberRef.FindOrAddRecord(record));
     }
 }
예제 #2
0
        internal int ImportMethodOrField(Type declaringType, string name, Signature sig)
        {
            int token;

            if (!importedMemberRefs.TryGetValue(new MemberRefKey(declaringType, name, sig), out token))
            {
                MemberRefTable.Record rec = new MemberRefTable.Record();
                rec.Class = GetTypeTokenForMemberRef(declaringType);
                rec.Name  = this.Strings.Add(name);
                ByteBuffer bb = new ByteBuffer(16);
                sig.WriteSig(this, bb);
                rec.Signature = this.Blobs.Add(bb);
                token         = 0x0A000000 | this.MemberRef.AddRecord(rec);
                importedMemberRefs.Add(new MemberRefKey(declaringType, name, sig), token);
            }
            return(token);
        }