0
0

FormatResultAttribute.cs 808 B

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. namespace ZhonTai.DynamicApi.Attributes;
  5. [Serializable]
  6. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
  7. public class FormatResultAttribute : ProducesResponseTypeAttribute
  8. {
  9. public FormatResultAttribute(int statusCode) : base(statusCode)
  10. {
  11. }
  12. public FormatResultAttribute(Type type) : base(type, StatusCodes.Status200OK)
  13. {
  14. FormatType(type);
  15. }
  16. public FormatResultAttribute(Type type, int statusCode) : base(type, statusCode)
  17. {
  18. FormatType(type);
  19. }
  20. private void FormatType(Type type)
  21. {
  22. if (type != null && type != typeof(void))
  23. {
  24. Type = AppConsts.FormatResultType.MakeGenericType(type);
  25. }
  26. }
  27. }