OpCodes.Callvirt Alan

Tanım

Bir nesne üzerinde geç bağlı bir yöntem çağırır ve dönüş değeri değerlendirme yığınına gönderiliyor.Calls a late-bound method on an object, pushing the return value onto the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Callvirt;
public static readonly System.Reflection.Emit.OpCode Callvirt;
 staticval mutable Callvirt : System.Reflection.Emit.OpCode
Public Shared ReadOnly Callvirt As OpCode 

Alan Değeri

OpCode

Açıklamalar

Aşağıdaki tabloda, yönergenin onaltılı ve Microsoft ara dil (MSIL) derleme biçimi ve kısa bir başvuru özeti listelenmektedir:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

BiçimlendirFormat Derleme biçimiAssembly Format DescriptionDescription
6F < T >6F < T > kısıt methodcallvirt method İle ilişkili belirli bir yöntemi çağırır obj .Calls a specific method associated with obj.

Yığın geçişli davranışı sıralı sırayla:The stack transitional behavior, in sequential order, is:

  1. Bir nesne başvurusu obj yığına gönderilir.An object reference obj is pushed onto the stack.

  2. Aracılığıyla Yöntem bağımsız değişkenleri arg1 argN yığına gönderilir.Method arguments arg1 through argN are pushed onto the stack.

  3. arg1 argN Ve nesne başvurusu aracılığıyla Yöntem bağımsız değişkenleri obj yığından alınır; Yöntem çağrısı bu bağımsız değişkenlerle gerçekleştirilir ve denetim obj Yöntem meta veri belirtecinin başvurduğu yönteme aktarılır.Method arguments arg1 through argN and the object reference obj are popped from the stack; the method call is performed with these arguments and control is transferred to the method in obj referred to by the method metadata token. Tamamlandığında, bir dönüş değeri, çağrılan yöntemi tarafından oluşturulur ve çağırana gönderilir.When complete, a return value is generated by the callee method and sent to the caller.

  4. Dönüş değeri yığına gönderilir.The return value is pushed onto the stack.

callvirtYönerge, bir nesne üzerinde geç bağlı bir yöntem çağırır.The callvirt instruction calls a late-bound method on an object. Diğer bir deyişle, yöntemi obj Yöntem İşaretçisinde görünür derleme zamanı sınıfı yerine çalışma zamanı türüne göre seçilir.That is, the method is chosen based on the runtime type of obj rather than the compile-time class visible in the method pointer. Callvirt hem sanal hem de örnek yöntemlerini çağırmak için kullanılabilir.Callvirt can be used to call both virtual and instance methods. callvirtYönerge, tail Tailcall Denetim aktarmadan önce geçerli yığın çerçevesinin serbest bırakılacağını belirtmek için hemen öncesinde bir () ön eki gelebilir.The callvirt instruction may be immediately preceded by a tail (Tailcall) prefix to specify that the current stack frame should be released before transferring control. Çağrı, denetimi özgün yöntemden daha yüksek bir güven yöntemine aktaracaksa yığın çerçevesi yayınlanmaz.If the call would transfer control to a method of higher trust than the original method the stack frame will not be released.

Yöntem meta veri belirteci, çağrılacak yöntemin adını, sınıfını ve imzasını sağlar.The method metadata token provides the name, class and signature of the method to call. İle ilişkili sınıfı, obj bir örnek olduğu sınıftır.The class associated with obj is the class of which it is an instance. Sınıf, belirtilen yöntem adı ve imzayla eşleşen statik olmayan bir yöntem tanımlıyorsa, bu yöntem çağrılır.If the class defines a non-static method that matches the indicated method name and signature, this method is called. Aksi takdirde, bu sınıfın temel sınıf zincirindeki tüm sınıflar sırayla denetlenir.Otherwise all classes in the base class chain of this class are checked in order. Hiçbir yöntem bulunamazsa hatadır.It is an error if no method is found.

Callvirt metodu çağırmadan önce nesneyi ve ilişkili bağımsız değişkenleri değerlendirme yığınında kapatır.Callvirt pops the object and the associated arguments off the evaluation stack before calling the method. Yöntemin bir dönüş değeri varsa, yöntem tamamlandıktan sonra yığına gönderilir.If the method has a return value, it is pushed on the stack upon method completion. Çağrılan tarafta, bağımsız değişken obj 1 olarak parametre olarak erişilir arg1 ve bu şekilde devam eder.On the callee side, the obj parameter is accessed as argument 0, arg1 as argument 1, and so on.

Bağımsız değişkenler yığına doğru sırayla yerleştirilir.The arguments are placed on the stack in left-to-right order. Diğer bir deyişle, ilk bağımsız değişken, yığına, sonra ikinci bağımsız değişken ise ikinci bağımsız değişken, sonra da tüm gerekli bağımsız değişkenler yığın olarak azalan sırada olacak şekilde hesaplanır ve yerleştirilir.That is, the first argument is computed and placed on the stack, then the second argument, then the third, until all necessary arguments are atop the stack in descending order. Örnek başvurusu obj (her zaman için gereklidir callvirt ), Kullanıcı tarafından görünen bağımsız değişkenlerden önce itilmiş olmalıdır.The instance reference obj (always required for callvirt) must be pushed before any of the user-visible arguments. İmza (meta veri belirtecinde gerçekleştirilen), Bu işaretçinin parametre listesinde bir girdi içermemelidir.The signature (carried in the metadata token) need not contain an entry in the parameter list for the this pointer.

Bir sanal yöntemin yönerge kullanılarak da çağrılabilecek olduğunu unutmayın Call .Note that a virtual method can also be called using the Call instruction.

MissingMethodException Belirtilen ada ve imzaya sahip statik olmayan bir yöntem, ile ilişkili sınıfta obj veya temel sınıflarından hiçbiriyle bulunamazsa oluşturulur.MissingMethodException is thrown if a non-static method with the indicated name and signature could not be found in the class associated with obj or any of its base classes. Bu genellikle, Microsoft ara dili (MSIL) yönergeleri çalışma zamanı yerine yerel koda dönüştürüldüğünde algılanır.This is typically detected when Microsoft Intermediate Language (MSIL) instructions are converted to native code, rather than at runtime.

NullReferenceException obj null ise oluşturulur.NullReferenceException is thrown if obj is null.

SecurityException Sistem güvenliği çağıran yönteme arayan erişimi vermezse oluşturulur.SecurityException is thrown if system security does not grant the caller access to the called method. Güvenlik denetimi, CıL 'nin çalışma süresi yerine yerel koda dönüştürülmesi durumunda meydana gelebilir.The security check may occur when the CIL is converted to native code rather than at run time.

Not

Değer türlerinde System. Object yöntemleri çağrılırken, constrained yönergeyle birlikte öneki kullanmayı düşünün callvirt .When calling methods of System.Object on value types, consider using the constrained prefix with the callvirt instruction. Bu, değer türünün yöntemi geçersiz kıldığına bağlı olarak farklı IL yayma gereksinimini ortadan kaldırır, böylece olası bir sürüm oluşturma sorunu önlenir.This removes the need to emit different IL depending on whether or not the value type overrides the method, avoiding a potential versioning problem. constrainedArabirim yöntemini uygulayan değer türü yöntemi bir kullanılarak değiştirilebiliyorsa, değer türlerinde arabirim yöntemleri çağrılırken ön eki kullanmayı düşünün MethodImpl .Consider using the constrained prefix when invoking interface methods on value types, since the value type method implementing the interface method can be changed using a MethodImpl. Bu sorunlar, Opcode içinde daha ayrıntılı olarak açıklanmıştır Constrained .These issues are described in more detail in the Constrained opcode.

Aşağıdaki Emit yöntem aşırı yüklemesi Opcode 'ı kullanabilir callvirt :The following Emit method overload can use the callvirt opcode:

Şunlara uygulanır