次のような API 応答があるとします。
<ApiException>
<Status>400</Status>
<Message>Foot too big for mouth</Message>
<ApiException>
というクラスを作成し、ApiException
それにシリアル化する方法を知っています。
public class ApiException
{
public string Status { get; set; }
public string Message { get; set; }
}
using (var response = ((HttpWebResponse)wex.Response))
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(ApiException));
ApiException ex = (ApiException)serializer.Deserialize(reader);
}
}
また、プロパティに要素名を指定する方法も知っています
public class ApiException
{
[System.Xml.Serialization.XmlElement(ElementName = "Status")]
public string Whut { get; set; }
[System.Xml.Serialization.XmlElement(ElementName = "Message")]
public string Why { get; set; }
}
しかし、すでに というクラスがある場合はどうなるApiException
でしょうか? 私はこれを呼び出したいと言うFootMouthAPIException
それを行う方法はありますか?クラス自体のデータ注釈でしょうか?