I want to create some classes, that have to look a certain way ( the way shown in my example). Some of the class properties are classes (or structs) themselves. I want to write a method within my classes that get the Property-Values of all the Properties, that are Structs and write them to a string.
So this is what my classes look like:
public class car
{
public string brand { get; set; }
public tire _id { get; set; }
public string GetAttributes()
{
Type type = this.GetType();
PropertyInfo[] properties = type.GetProperties();
foreach(PropertyInfo propertyInfo in properties)
if (propertyInfo.PropertyType.ToString().Contains("_"))
{
//I want to write the actual value of the property here!
string nested_property_value = ...
return nested_property_value;
}
}
}
this is what my structs look like:
public struct tire
{
public int id { get; set; }
}
this would be the Main Program:
tire mynewtire = new tire()
{
id = 5
};
car mynewcar = new car()
{
_id = mynewtire
};
Anyone has an idea how to create the GetAttributes-Methode? I've been trying to figure this out for ages now, but don't get there...