I have to implement some protocol. All of xmls that I need to serialize(WCF contracts) have always two specified sections and one "content" section - e.g.:
First:
<X>
<Y>
<Content1/>
</Y>
</X>
Second:
<X>
<Y>
<Content2/>
</Y>
</X>
I want to use some generics, but then problem with node name appeared. I found this answer : Serialization DataMember (name) override issue but it doesn't fit for me.
Code for my approach:
public class X<TContent>
{
[DataMember]
public Y<TContent> yName { get; set; }
}
public class Y<TContent>
{
[DataMember]
public virtual TContent Content { get; set; }
}
And then there is few "Content" classes like:
public sealed class Content1Class: Y<Content1>
{
[DataMember(Name = nameof(Content1))]
public override Content1 Content { get; set; }
}
Unfortunately I have always null for Content.
My question is: Can I set attributes and relations between classes to deserialize the above-mentioned case? Maybe I have to create separate classes for each content type?