BindingChainException.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. namespace Avalonia.Data
  5. {
  6. /// <summary>
  7. /// An exception returned through <see cref="BindingNotification"/> signaling that a
  8. /// requested binding expression could not be evaluated because of a null in one of the links
  9. /// of the binding chain.
  10. /// </summary>
  11. public class BindingChainException : Exception
  12. {
  13. private string _message;
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="BindingChainException"/> class.
  16. /// </summary>
  17. public BindingChainException()
  18. {
  19. }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="BindingChainException"/> class.
  22. /// </summary>
  23. /// <param name="message">The error message.</param>
  24. public BindingChainException(string message)
  25. {
  26. _message = message;
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="BindingChainException"/> class.
  30. /// </summary>
  31. /// <param name="message">The error message.</param>
  32. /// <param name="expression">The expression.</param>
  33. /// <param name="errorPoint">
  34. /// The point in the expression at which the error was encountered.
  35. /// </param>
  36. public BindingChainException(string message, string expression, string errorPoint)
  37. {
  38. _message = message;
  39. Expression = expression;
  40. ExpressionErrorPoint = errorPoint;
  41. }
  42. /// <summary>
  43. /// Gets the expression that could not be evaluated.
  44. /// </summary>
  45. public string Expression { get; protected set; }
  46. /// <summary>
  47. /// Gets the point in the expression at which the error occurred.
  48. /// </summary>
  49. public string ExpressionErrorPoint { get; protected set; }
  50. /// <inheritdoc/>
  51. public override string Message
  52. {
  53. get
  54. {
  55. if (Expression != null && ExpressionErrorPoint != null)
  56. {
  57. return $"{_message} in expression '{Expression}' at '{ExpressionErrorPoint}'.";
  58. }
  59. else if (ExpressionErrorPoint != null)
  60. {
  61. return $"{_message} in expression '{ExpressionErrorPoint}'.";
  62. }
  63. else
  64. {
  65. return $"{_message} in expression.";
  66. }
  67. }
  68. }
  69. }
  70. }