I have a class which contains a property who's type is another class. For example:
public class Outer
{
public string SomeStringProperty { get; set; }
public Inner SomeClassProperty { get; set; }
}
public class Inner
{
public string InnerProperty1 { get; set; }
public string InnerProperty2 { get; set; }
}
I want to convert an instance of the Outer
class to a URL query string, and include the properties from the nested Inner
class.
For example, given an instance of Outer
, such as:
Outer toSerialise = new Outer
{
SomeStringProperty = "MyOuterValue",
SomeClassProperty = new Inner
{
InnerProperty1 = "MyInnerValue1",
InnerProperty2 = "MyInnerValue2"
}
};
I want to convert this to a string of:
&SomeStringProperty=MyOuterValue&InnerProperty1=MyInnerValue1&InnerProperty2=MyInnerValue2
How can I achieve this?
I've found answers to similar questions, however they don't seem to support nested classes.