private string getPropiedades(Type tipo) { string codigo = ""; PropertyInfo[] propiedades; // Propiedades públicas codigo += this.SALTO; codigo += "//[PROPIEDADES PÚBLICAS]"; codigo += this.SALTO; propiedades = this.tipoDeClase.GetProperties(); foreach (PropertyInfo atributo in propiedades) { MethodInfo metodo = atributo.GetGetMethod(); // String ambito = metodo.GetMethodBody().GetILAsByteArray().ToString(); String ambito = ""; ambito = this.getAmbito(metodo); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + atributo.PropertyType + "},{\" + obj." + atributo.Name + " + \"},{\"" + atributo.GetValue(this.clase, null) + "\"}},\";"; } // Propiedades privadas y protegidas codigo += this.SALTO; codigo += "//[PROPIEDADES PRIVADAS Y PROTEGIDAS]"; codigo += this.SALTO; propiedades = this.tipoDeClase.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic); foreach (PropertyInfo atributo in propiedades) { String ambito = ""; if (atributo.GetGetMethod() != null) { ambito = this.getAmbito(atributo.GetGetMethod()); } codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + atributo.PropertyType + "},{\" + obj." + atributo.Name + " + \"},{\"" + atributo.GetValue(this.clase, null) + "\"}},\";"; } // Propiedades privadas estáticas codigo += this.SALTO; codigo += "//[PROPIEDADES PRIVADAS ESTÁTICAS]"; codigo += this.SALTO; // FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic); foreach (FieldInfo field in fieldInfos) { String ambito = this.getAmbitoField(field); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + field.FieldType + "},{\" + obj." + field.Name + " + \"},{\"" + field.GetValue(this.clase) + "\"}},\";"; } // Propiedades públicas estáticas codigo += this.SALTO; codigo += "//[PROPIEDADES PÚBLICAS ESTÁTICAS]"; codigo += this.SALTO; // FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fieldInfos) { String ambito = this.getAmbitoField(field); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + field.FieldType + "},{\" + obj." + field.Name + " + \"},{\"" + field.GetValue(this.clase) + "\"}},\";"; } // Otras propiedades complejas (OJO, aparecen también estáticas) codigo += this.SALTO; codigo += "[MIEMBROS]"; codigo += this.SALTO; MemberInfo[] miembros = this.tipoDeClase.GetMembers(); foreach (MemberInfo miembro in miembros) { if (miembro.MemberType.ToString() != "Method" && miembro.MemberType.ToString() != "Constructor" && miembro.MemberType.ToString() != "Property" // Ya estaban identificadas antes con PropertyInfo ) { codigo += this.SALTO + this.TAB + this.TAB; /* * Type tipo1 = Type.GetType(miembro.GetProperty("FieldType").ToString()); * codigo += "Tipo de miembro " + tipo1.ToString(); */ MemberTypes tipoDeMiembro = miembro.MemberType; if (tipoDeMiembro.ToString() == "NestedType") { if (tipoDeMiembro.GetType().IsEnum) { codigo += this.SALTO + this.TAB + this.TAB; codigo += "// A continuación se declara el tipo " + miembro.GetType().ReflectedType + " - " + miembro.Name + ""; codigo += Type.GetTypeCode(miembro.GetType()).ToString(); } } else { codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{" + miembro.MemberType.ToString() + "},{\" + obj." + miembro.Name + " + \"}},\";"; } /* codigo += miembro.ReflectedType; // Indica el tipo de miembro que es * codigo += this.SALTO; * codigo += miembro.DeclaringType; // Indica la clase de este miembro * codigo += this.SALTO; * codigo += miembro.GetType(); // Tipo de objeto del campo * codigo += this.SALTO; */ } } return(codigo); }