fork download
  1. using System;
  2. using System.IO;
  3. using System.Xml.Serialization;
  4.  
  5. namespace Code.Without.IDE
  6. {
  7.  
  8. [AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue, Inherited = true)]
  9. public class XmlInheritIgnoreAttribute : System.Xml.Serialization.XmlIgnoreAttribute
  10. {
  11. }
  12.  
  13. [Serializable]
  14. public abstract class C1
  15. {
  16. [XmlInheritIgnore]
  17. public abstract bool IsValid_C1 { get; set;}
  18. }
  19.  
  20. [Serializable]
  21. public class C2 : C1
  22. {
  23. public bool IsValid_C2 { get; set; }
  24.  
  25. public override bool IsValid_C1 { get; set;}
  26.  
  27. public C2()
  28. {
  29. IsValid_C1 = true;
  30. IsValid_C2 = false;
  31. }
  32. }
  33.  
  34. public static class AbstractPropertiesAttributeTest
  35. {
  36. public static void Main(string[] args)
  37. {
  38. C2 c2 = new C2();
  39. using(MemoryStream ms = new MemoryStream())
  40. {
  41. XmlSerializer ser = new XmlSerializer(typeof(C2));
  42. ser.Serialize(ms, c2);
  43. string result = System.Text.Encoding.UTF8.GetString(ms.ToArray());
  44. Console.WriteLine(result);
  45. }
  46. }
  47. }
  48. }
Success #stdin #stdout 0.22s 40712KB
stdin
Standard input is empty
stdout
<?xml version="1.0" encoding="utf-8"?>
<C2 xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance" xmlns:xsd="http://w...content-available-to-author-only...3.org/2001/XMLSchema">
  <IsValid_C2>false</IsValid_C2>
  <IsValid_C1>true</IsValid_C1>
</C2>