OpCodes.Newobj Pole
Definicja
Tworzy nowy obiekt lub nowe wystąpienie typu wartości, wypchnięcie odwołania do obiektu (typu O
) na stos oceny.Creates a new object or a new instance of a value type, pushing an object reference (type O
) onto the evaluation stack.
public: static initonly System::Reflection::Emit::OpCode Newobj;
public static readonly System.Reflection.Emit.OpCode Newobj;
staticval mutable Newobj : System.Reflection.Emit.OpCode
Public Shared ReadOnly Newobj As OpCode
Wartość pola
Uwagi
W poniższej tabeli przedstawiono format zestawu języka pośredniego w formacie szesnastkowym i Microsoft (MSIL) instrukcji wraz z krótkim podsumowaniem odwołania:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:
FormatFormat | Format zestawuAssembly Format | OpisDescription |
---|---|---|
73 < T >73 < T > |
newobj ctor newobj ctor |
Alokuje niezainicjowany typ obiektu lub wartości i wywołuje metodę konstruktora ctor .Allocates an uninitialized object or value type and calls the constructor method ctor . |
Zachowanie przejściowe stosu, w kolejności sekwencyjnej, to:The stack transitional behavior, in sequential order, is:
Argumenty
arg1
przezargn
są wypychane na stosie w sekwencji.Argumentsarg1
throughargn
are pushed on the stack in sequence.Argumenty
argn
przezarg1
są zdjęte ze stosu i przechodzą doctor
tworzenia obiektów.Argumentsargn
througharg1
are popped from the stack and passed toctor
for object creation.Odwołanie do nowego obiektu jest wypychane do stosu.A reference to the new object is pushed onto the stack.
newobj
Instrukcja tworzy nowy obiekt lub nowe wystąpienie typu wartości.The newobj
instruction creates a new object or a new instance of a value type. Ctor
jest tokenem metadanych ( methodref
lub methoddef
, który musi być oznaczony jako Konstruktor), który wskazuje nazwę, klasę i podpis konstruktora do wywołania.Ctor
is a metadata token (a methodref
or methoddef
that must be marked as a constructor) that indicates the name, class and signature of the constructor to call.
newobj
Instrukcja przydziela nowe wystąpienie klasy skojarzonej z ctor
i inicjuje wszystkie pola w nowym wystąpieniu do 0 (odpowiedniego typu) lub odwołania o wartości null zgodnie z potrzebami.The newobj
instruction allocates a new instance of the class associated with ctor
and initializes all the fields in the new instance to 0 (of the proper type) or null references as appropriate. Następnie wywołuje konstruktora ctor
z podanym argumentami wraz z nowo utworzonym wystąpieniem.It then calls the constructor ctor
with the given arguments along with the newly created instance. Po wywołaniu konstruktora, aktualnie zainicjowany odwołanie do obiektu (Type O
) jest wypychane na stosie.After the constructor has been called, the now initialized object reference (type O
) is pushed on the stack.
Z punktu widzenia konstruktora Niezainicjowany obiekt jest argumentem 0, a pozostałe argumenty przekazane do newobj są zgodne z kolejnością.From the constructor's point of view, the uninitialized object is argument 0 and the other arguments passed to newobj follow in order.
Wszystkie tablice jednowymiarowe oparte na zero są tworzone przy użyciu Newarr , nie newobj
.All zero-based, one-dimensional arrays are created using Newarr, not newobj
. Z drugiej strony, wszystkie inne tablice (więcej niż jeden wymiar lub jednowymiarowe, ale nie zero) są tworzone przy użyciu newobj
.On the other hand, all other arrays (more than one dimension, or one-dimensional but not zero-based) are created using newobj
.
Typy wartości nie są zwykle tworzone przy użyciu newobj
.Value types are not usually created using newobj
. Są one zazwyczaj przydzieleni jako argumenty lub zmienne lokalne, przy użyciu newarr
(dla tablic jednowymiarowych lub z jednowymiarowe) lub jako pola obiektów.They are usually allocated either as arguments or local variables, using newarr
(for zero-based, one-dimensional arrays), or as fields of objects. Po przydzieleniu są one inicjowane przy użyciu Initobj .Once allocated, they are initialized using Initobj. Jednakże newobj
instrukcji można użyć do utworzenia nowego wystąpienia typu wartości na stosie, który można następnie przesłać jako argument, przechowywany w lokalnej itd.However, the newobj
instruction can be used to create a new instance of a value type on the stack, that can then be passed as an argument, stored in a local, and so on.
OutOfMemoryException jest zgłaszany w przypadku braku wystarczającej ilości pamięci do spełnienia żądania.OutOfMemoryException is thrown if there is insufficient memory to satisfy the request.
MissingMethodException jest zgłaszany, jeśli nie można odnaleźć metody konstruktora ctor
o wskazanej nazwie, klasie i podpisie.MissingMethodException is thrown if a constructor method ctor
with the indicated name, class and signature could not be found. Jest to zwykle wykrywane, gdy instrukcje języka pośredniego (MSIL) firmy Microsoft są konwertowane na kod natywny, a nie w czasie wykonywania.This is typically detected when Microsoft Intermediate Language (MSIL) instructions are converted to native code, rather than at runtime.
Następujące Emit Przeciążenie metody może używać newobj
kodu operacji:The following Emit method overload can use the newobj
opcode: