You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
957 B

11 months ago
11 months ago
11 months ago
11 months ago
  1. using System;
  2. namespace Apewer.Web
  3. {
  4. /// <summary>表示 API 行为结果,主体为文本。</summary>
  5. public class TextResult : BytesResult
  6. {
  7. string _text;
  8. /// <summary>Body 文本。</summary>
  9. public virtual string Text { get => _text; set => SetText(value); }
  10. /// <summary>Body 字节数组。</summary>
  11. public override byte[] Bytes { get => base.Bytes; set => throw new NotSupportedException(); }
  12. /// <summary>创建结果实例。</summary>
  13. public TextResult(string text, string contentType = "text/plain") : base(null, contentType) => SetText(text);
  14. /// <summary>创建结果实例。</summary>
  15. public TextResult(int status, string text, string contentType = "text/plain") : base(status, null, contentType) => SetText(text);
  16. void SetText(string text)
  17. {
  18. _text = text;
  19. base.Bytes = text.Bytes();
  20. }
  21. }
  22. }