| ■No101350 (kiku さん) に返信 > 提示頂いたstackoverflow内にシンプルな実装というものがあり、 > こちらも試してみたいと思います。
stackoverflow内の下記のシンプルな実装の方も試してみました。 使い方がシンプルでとても良いのですが、 ReadXmlメソッドを独自にすべて実装する必要が発生し、 XmlSerializerクラスを利用する最大のメリットが 失われてしまうと思いました。
なんか中間的な良いアイデアはないでしょうか? ちょっとしばらく考えてみます。 皆さん、何かアイデアがあればヒントでも良いので 教えて欲しいです。
public class Foo : IXmlSerializable { [XmlComment(Value = "The application version, NOT the file version!")] public string Version { get; set; } public string Name { get; set; }
public void WriteXml(XmlWriter writer) { var properties = GetType().GetProperties();
foreach (var propertyInfo in properties) { if (propertyInfo.IsDefined(typeof(XmlCommentAttribute), false)) { writer.WriteComment( propertyInfo.GetCustomAttributes(typeof(XmlCommentAttribute), false) .Cast<XmlCommentAttribute>().Single().Value); }
writer.WriteElementString(propertyInfo.Name, propertyInfo.GetValue(this, null).ToString()); } } public XmlSchema GetSchema() { throw new NotImplementedException(); }
public void ReadXml(XmlReader reader) { throw new NotImplementedException(); } } |