2
0

TextSyndicationContent.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Syndication
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. using System.Xml;
  10. using System.Xml.Schema;
  11. using System.Xml.Serialization;
  12. using System.Runtime.CompilerServices;
  13. // NOTE: This class implements Clone so if you add any members, please update the copy ctor
  14. [TypeForwardedFrom("System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  15. public class TextSyndicationContent : SyndicationContent
  16. {
  17. string text;
  18. TextSyndicationContentKind textKind;
  19. public TextSyndicationContent(string text) : this(text, TextSyndicationContentKind.Plaintext)
  20. {
  21. }
  22. public TextSyndicationContent(string text, TextSyndicationContentKind textKind)
  23. {
  24. if (!TextSyndicationContentKindHelper.IsDefined(textKind))
  25. {
  26. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("textKind"));
  27. }
  28. this.text = text;
  29. this.textKind = textKind;
  30. }
  31. protected TextSyndicationContent(TextSyndicationContent source)
  32. : base(source)
  33. {
  34. if (source == null)
  35. {
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
  37. }
  38. this.text = source.text;
  39. this.textKind = source.textKind;
  40. }
  41. public string Text
  42. {
  43. get { return this.text; }
  44. }
  45. public override string Type
  46. {
  47. get
  48. {
  49. switch (this.textKind)
  50. {
  51. case TextSyndicationContentKind.Html:
  52. return Atom10Constants.HtmlType;
  53. case TextSyndicationContentKind.XHtml:
  54. return Atom10Constants.XHtmlType;
  55. default:
  56. return Atom10Constants.PlaintextType;
  57. }
  58. }
  59. }
  60. public override SyndicationContent Clone()
  61. {
  62. return new TextSyndicationContent(this);
  63. }
  64. protected override void WriteContentsTo(XmlWriter writer)
  65. {
  66. string val = this.text ?? string.Empty;
  67. if (this.textKind == TextSyndicationContentKind.XHtml)
  68. {
  69. writer.WriteRaw(val);
  70. }
  71. else
  72. {
  73. writer.WriteString(val);
  74. }
  75. }
  76. }
  77. }