ResultValueDto.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.Json.Serialization;
  5. using Quadarax.Foundation.Core.Exceptions;
  6. namespace Quadarax.Foundation.Core.Data.Interface.Entity.Dto
  7. {
  8. public class ResultValueDto<TDto> : ResultDto where TDto : IDto, new()
  9. {
  10. [JsonPropertyName("value")] public TDto Value { get; set; }
  11. public ResultValueDto(TDto value) : this()
  12. {
  13. Value = value;
  14. }
  15. public ResultValueDto() : base(new List<IError>())
  16. {
  17. Value = new TDto();
  18. }
  19. public ResultValueDto(CodeException[] exceptions) : base(exceptions.Select(x => new ErrorMessageDto(x)))
  20. {
  21. }
  22. public ResultValueDto(Exception exception) : base(new[]
  23. {
  24. exception is CodeException codeException
  25. ? new ErrorMessageDto(codeException)
  26. : new ErrorMessageDto(exception, -1)
  27. })
  28. {
  29. }
  30. public override object GetValue()
  31. {
  32. return Value;
  33. }
  34. public TDto GetValueAs()
  35. {
  36. return Value;
  37. }
  38. }
  39. public class ResultValueDto: ResultDto
  40. {
  41. [JsonPropertyName("value")]
  42. public object Value { get; set; }
  43. public ResultValueDto(object value) : this()
  44. {
  45. Value = value;
  46. }
  47. public ResultValueDto() : base(new List<IError>())
  48. {
  49. Value = null;
  50. }
  51. public ResultValueDto(CodeException[] exceptions) : base(exceptions.Select(x => new ErrorMessageDto(x)))
  52. {
  53. }
  54. public ResultValueDto(Exception exception) : base( new []{ exception is CodeException codeException ? new ErrorMessageDto(codeException) : new ErrorMessageDto(exception, -1)})
  55. {
  56. }
  57. public override object GetValue()
  58. {
  59. return Value;
  60. }
  61. public object GetValueAs()
  62. {
  63. return Value;
  64. }
  65. }
  66. }