Beispiel #1
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (Code == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "Code");
     }
     if (Message == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "Message");
     }
     if (Details != null)
     {
         foreach (var element in Details)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
     if (Innererror != null)
     {
         Innererror.Validate();
     }
 }
        public override string ToString()
        {
            if (_innererror is Exception)
            {
                dynamic innererrordyn = Innererror;
                var     exception     = new Dictionary <string, object>();
                exception.Add("message", innererrordyn.Message);
                exception.Add("stacktrace", innererrordyn.StackTrace);
                exception.Add("type", Innererror.GetType().Name);
                _innererror = exception;
            }
            var json = JsonConvert.SerializeObject(this);

            return(json);
        }
        internal void PrettyPrint(StringBuilder sb, string indentation = "")
        {
            sb.AppendLine($"{indentation}Code={Code}, Message={Message}");
            if (Details != null)
            {
                foreach (var detail in Details)
                {
                    detail.PrettyPrint(sb, $"{indentation}    ");
                }
            }

            if (Innererror != null)
            {
                Innererror.PrettyPrint(sb, $"{indentation}  ");
            }
        }