Advertisement
Fhernd

UsoGetMethodInfo.cs

Jul 28th, 2014
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace Recetas.Cap03
  5. {
  6.     internal class UsoGetMethodInfo
  7.     {
  8.         public void MetodoA(int i, int j) { }
  9.        
  10.         public void MetodoA(int[] i) { }
  11.        
  12.         public unsafe void MetodoA(int* i) { }
  13.        
  14.         public void MetodoA(ref int r) { }
  15.        
  16.         public void MetodoA( int i, out int o)
  17.         {
  18.             o = 101;
  19.         }
  20.        
  21.         public static void Main()
  22.         {
  23.             MethodInfo infoMetodo;
  24.            
  25.             // Búsqueda del método con la firma MetodoA(int i, int j):
  26.             infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
  27.                                 new Type[] {typeof(int), typeof(int) });
  28.            
  29.             Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
  30.            
  31.             // Búsqueda del método con la firma Metodo(int[]):
  32.             infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
  33.                                new Type[] {typeof(int[])});
  34.                                
  35.             Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
  36.            
  37.             // Búsqueda método con la firma MetodoA(int*):
  38.             infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
  39.                                new Type[] { typeof(int).MakePointerType()});
  40.                                
  41.             Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
  42.            
  43.             // Búsqueda método con la firma MetodoA(ref int):
  44.             infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
  45.                                 new Type[] {typeof(int).MakeByRefType()});
  46.                                
  47.             Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
  48.            
  49.             // Búsqueda método con la firma MetodoA(int, out int):
  50.             infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
  51.                                 new Type[] {typeof(int), typeof(int).MakeByRefType()});
  52.            
  53.             Console.WriteLine("\nNombre completo método: {0}\n", infoMetodo);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement