Advertisement
Fhernd

ObtencionMiembrosConReflection.cs

Aug 29th, 2014
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. // ===++===
  2. //
  3. //    OrtizOL
  4. //
  5. // ===--===
  6. /*============================================================
  7. //
  8. // Clase: ObtencionMiembrosConReflection.cs
  9. //
  10. // Propósito: Demostración del descubrimiento de miembros
  11. // de un tipo con Reflection.
  12. //
  13. ============================================================*/
  14.  
  15. using System;
  16. using System.Reflection;
  17.  
  18. namespace Recetas.Cap03
  19. {
  20.     // Clase de ejemplo para uso de reflection:
  21.     public sealed class ObtencionMiembrosConReflection
  22.     {
  23.         public static void Main()
  24.         {
  25.             // Obtención representación `Type` de `ObtencionMiembrosConReflection`:
  26.             Type tipo = typeof(ObtencionMiembrosConReflection);
  27.            
  28.             // Descubrimios los constructores public:
  29.             Console.WriteLine ("\n === Constructores de `{0}` === \n", typeof(ObtencionMiembrosConReflection).Name.ToString());
  30.             foreach (ConstructorInfo ctor in tipo.GetConstructors())
  31.             {
  32.                 Console.WriteLine ("\tConstructor: {0}", ctor.ToString());
  33.                 // Parámetros para el constructor actual en `ctor`:
  34.                 foreach (ParameterInfo parametro in ctor.GetParameters())
  35.                 {
  36.                     Console.WriteLine ("\t{0} ({1})", parametro.Name.ToString(), parametro.ParameterType.ToString());
  37.                 }
  38.                 Console.WriteLine ();
  39.             }
  40.            
  41.             // Descubrimios los métodos public:
  42.             Console.WriteLine ("\n === Métodos de `{0}` === \n", typeof(ObtencionMiembrosConReflection).Name.ToString());
  43.             foreach (MethodInfo metodo in tipo.GetMethods())
  44.             {
  45.                 Console.WriteLine ("\tMétodo: {0}", metodo.ToString());
  46.                 // Parámetros para el construmetodo actual en `metodo`:
  47.                 foreach (ParameterInfo parametro in metodo.GetParameters())
  48.                 {
  49.                     Console.WriteLine ("\t{0} ({1})", parametro.Name.ToString(), parametro.ParameterType.ToString());
  50.                 }
  51.                 Console.WriteLine ();
  52.             }
  53.            
  54.             // Descubrimos las propiedades:
  55.             Console.WriteLine ("\n === Propiedades de `{0}` === \n", typeof(ObtencionMiembrosConReflection).Name.ToString());
  56.             foreach (PropertyInfo propiedad in tipo.GetProperties())
  57.             {
  58.                 Console.WriteLine ("\tPropiedad: {0}", propiedad.ToString());
  59.                 // Muestra las funciones de acceso de esta propiedad:
  60.                 foreach (MethodInfo funcionAcceso in propiedad.GetAccessors())
  61.                 {
  62.                     Console.WriteLine ("\t{0}", funcionAcceso.Name.ToString());
  63.                 }
  64.                 Console.WriteLine ();
  65.             }
  66.         }
  67.        
  68.         public string Propiedad
  69.         {
  70.             get;
  71.             set;
  72.         }
  73.        
  74.         public ObtencionMiembrosConReflection(string param1, string param2, int param3)
  75.         {
  76.        
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement