public static void Main()
Console.WriteLine(c.ToJson());
public string Marca {get; set;}
public int Puertas{get; set;}
public int Modelo{get; set;}
public Motor motor {get; set;}
string methodName = "ToJson";
foreach(var property in this.GetType().GetProperties()){
json += property.Name + ":";
if(property.GetValue(this, null) != null){
var valuetmp = property.GetValue(this, null);
if(valuetmp.GetType().GetMethod(methodName) != null){
json += valuetmp.GetType().GetMethod(methodName).Invoke(valuetmp,null);
json += valuetmp.ToString();
public int Cilindraje{get; set;}
public int Valvulas{get; set;}
public int? Cid{get;set;}
public Otro otro{get;set;}
string methodName = "ToJson";
foreach(var property in this.GetType().GetProperties()){
json += property.Name + ":";
if(property.GetValue(this, null) != null){
var valuetmp = property.GetValue(this, null);
if(valuetmp.GetType().GetMethod(methodName) != null){
json += valuetmp.GetType().GetMethod(methodName).Invoke(valuetmp,null);
json += valuetmp.ToString();
public string a {get; set;}
public string b {get; set;}
public string c {get; set;}
string methodName = "ToJson";
foreach(var property in this.GetType().GetProperties()){
json += property.Name + ":";
if(property.GetValue(this, null) != null){
var valuetmp = property.GetValue(this, null);
if(valuetmp.GetType().GetMethod(methodName) != null){
json += valuetmp.GetType().GetMethod(methodName).Invoke(valuetmp,null);
json += valuetmp.ToString();