Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/07/2013, 14:47
Avatar de halexander
halexander
 
Fecha de Ingreso: abril-2010
Ubicación: En algun lugar de mexico xD
Mensajes: 59
Antigüedad: 14 años
Puntos: 0
Pregunta Modificar propiedades de clase con Reflection

Hola, buen día!!

Tengo tres clases:

Código C++:
Ver original
  1. public partial class Comprobante
  2. {
  3. private ClasePersona _persona;
  4. private string _carrera;
  5.  
  6. public string Carrera
  7.         {
  8.             get
  9.             {
  10.                 return this._carrera;
  11.             }
  12.             set
  13.             {
  14.                 this._carrera = value;
  15.             }
  16.         }
  17.  
  18.  
  19. public ClasePersona Persona
  20.         {
  21.             get
  22.             {
  23.                 return this._persona;
  24.             }
  25.             set
  26.             {
  27.                 this._persona= value;
  28.             }
  29.         }
  30.  
  31. }
  32.  
  33. public partial class ClasePersona
  34. {
  35. private ClaseDomicilio _domicilio;
  36. private string _dato;
  37.  
  38. public ClaseDomicilio DomicilioFiscal
  39.         {
  40.             get
  41.             {
  42.                 return this._domicilio;
  43.             }
  44.             set
  45.             {
  46.                 this._domicilio = value;
  47.             }
  48.         }
  49.  
  50. public string Dato
  51.         {
  52.             get
  53.             {
  54.                 return this._dato;
  55.             }
  56.             set
  57.             {
  58.                 this._dato = value;
  59.             }
  60.         }
  61. }
  62.  
  63. public partial class ClaseDomicilio
  64. {
  65. private string _calle;
  66.  
  67.         private string _noExterior;
  68.  
  69.         private string _noInterior;
  70.  
  71. public string Calle
  72.         {
  73.             get
  74.             {
  75.                 return this._calle;
  76.             }
  77.             set
  78.             {
  79.                 this._calle = value;
  80.             }
  81.         }
  82.         public string NoExterior
  83.         {
  84.             get
  85.             {
  86.                 return this._noExterior;
  87.             }
  88.             set
  89.             {
  90.                 this._noExterior = value;
  91.             }
  92.         }
  93.         public string NoInterior
  94.         {
  95.             get
  96.             {
  97.                 return this._noInterior;
  98.             }
  99.             set
  100.             {
  101.                 this._noInterior = value;
  102.             }
  103.         }
  104.  
  105. }

y quiero acceder a ellos mediante Reflection y cambiar el valor de sus propiedades mediante el SET, pero me lanza este error:

El objeto de tipo 'System.String' no puede convertirse en el tipo 'Comprobante'.

las lineas de mi codigo son:

Código C++:
Ver original
  1. Comprobante comprobante = new Comprobante();
  2. Type tipo = comprobante.GetType();
  3.  
  4.  PropertyInfo propiedad = tipo.GetProperty(strNombrePropiedad);
  5.  propiedad.SetValue(comprobante.Persona.Carrera, strValor, null);

alguna idea?

De antemano, muchas gracias.