Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
Type.MakeByRefType, méthode
Retourne un objet Type qui représente le type actuel lorsqu'il est passé en tant que paramètre ref (paramètre ByRef en Visual Basic).
Assembly : mscorlib (dans mscorlib.dll)
| Exception | Condition |
|---|---|
| NotSupportedException |
La méthode appelée n'est pas prise en charge dans la classe de base. |
| TypeLoadException |
Le type actuel est TypedReference. ou Le type actuel est un type ByRef. En d'autres termes, Type.IsByRef retourne la valeur true. |
L'exemple de code suivant crée un tableau, ref (ByRef en Visual Basic), et des type pointeur pour la classe Test.
using System; using System.Reflection; public class Example { public static void Main() { // Create a Type object that represents a one-dimensional // array of Example objects. Type t = typeof(Example).MakeArrayType(); Console.WriteLine("\r\nArray of Example: {0}", t); // Create a Type object that represents a two-dimensional // array of Example objects. t = typeof(Example).MakeArrayType(2); Console.WriteLine("\r\nTwo-dimensional array of Example: {0}", t); // Demonstrate an exception when an invalid array rank is // specified. try { t = typeof(Example).MakeArrayType(-1); } catch(Exception ex) { Console.WriteLine("\r\n{0}", ex); } // Create a Type object that represents a ByRef parameter // of type Example. t = typeof(Example).MakeByRefType(); Console.WriteLine("\r\nByRef Example: {0}", t); // Get a Type object representing the Example class, a // MethodInfo representing the "Test" method, a ParameterInfo // representing the parameter of type Example, and finally // a Type object representing the type of this ByRef parameter. // Compare this Type object with the Type object created using // MakeByRefType. Type t2 = typeof(Example); MethodInfo mi = t2.GetMethod("Test"); ParameterInfo pi = mi.GetParameters()[0]; Type pt = pi.ParameterType; Console.WriteLine("Are the ByRef types equal? {0}", (t == pt)); // Create a Type object that represents a pointer to an // Example object. t = typeof(Example).MakePointerType(); Console.WriteLine("\r\nPointer to Example: {0}", t); } // A sample method with a ByRef parameter. // public void Test(ref Example e) { } } /* This example produces output similar to the following: Array of Example: Example[] Two-dimensional array of Example: Example[,] System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.RuntimeType.MakeArrayType(Int32 rank) in c:\vbl\ndp\clr\src\BCL\System\RtType.cs:line 2999 at Example.Main() ByRef Example: Example& Are the ByRef types equal? True Pointer to Example: Example* */
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.