このようなもの?私の理解が正しければ、属性によって装飾されたクラスのすべてのプロパティが必要です。JSON.NET 参照を含めたくなかったので、XmlText代わりに属性を使用しました。
[Test]
public void dummy()
{
var conditions = new Conditions();
var propertyInfos = conditions.GetType().GetProperties();
propertyInfos.ForEach(x =>
{
var attrs = x.GetCustomAttributes(true);
if (attrs.Any(p => p.GetType() == typeof(XmlTextAttribute)))
{
Console.WriteLine("{0} {1}", x, attrs.Aggregate((o, o1) => string.Format("{0},{1}",o,o1)));
}
});
}
そして、クラスは次のようになります -
[XmlType]
public class Conditions
{
[XmlText]
public DateTime? OpenedSince { get; set; }
[XmlText]
public DateTime? AddedUntil { get; set; }
[XmlText]
public DateTime? OpenedUntil { get; set; }
[XmlText]
public DateTime? ArchivedUntil { get; set; }
public string NotTobeListed { get; set; }
}
コンソール出力:
System.Nullable`1[System.DateTime] OpenedSince System.Xml.Serialization.XmlTextAttribute
System.Nullable`1[System.DateTime] AddedUntil System.Xml.Serialization.XmlTextAttribute
System.Nullable`1[System.DateTime] OpenedUntil System.Xml.Serialization.XmlTextAttribute
System.Nullable`1[System.DateTime] ArchivedUntil System.Xml.Serialization.XmlTextAttribute
NotToBeListed表示されないことに注意してください。