I want to (de)serialize internal classes.
internal class Data
{
public string? Name { get; set; }
public string? Type { get; set; }
public List<DataWithAttribute> DataList { get; set; }
}
internal class DataWithAttribute
{
public string? FirstAttribute { get; set; }
public string? SecondAttribute { get; set; }
}
to get xml
<Data>
<Name>Some name</Name>
<Type>Some value</Type>
<DataList>
<DataWithAttribute FirstAttribute="some value" SecondAttribute="some value" />
<DataWithAttribute FirstAttribute="some value" SecondAttribute="some value" />
<DataWithAttribute FirstAttribute="some value" SecondAttribute="some value" />
</DataList>
</Data>
I cannot write real code and data (because NDA)
I tried XmlSerializer, but It requires public classes.
So, I tried DataContractSerializer: it works with internal, but it doesn't support attributes.
<Data FirstAttribute="1" SecondAttribute="2"/>? In that case I think you need to rethink your structure, as a list of similar attributes doesn't make much sense.DataWithAttributeliterally is a list. Anyway you cannot use complex types for xml-attributes. You have to serialize every attribute seperatly to a simple type.