aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs
blob: 41d53bf2a3ea3273077dd3b2f6b5aec872b42be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.BL.DTO
{
    public class HardwareMotorDTO : HardwareMotorDTOBase
    {

    }
}
al.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


/// <summary>
/// Contains <see cref="Exception"/> exception methods.
/// </summary>
public static class ExceptionExtensions
{
    /// <summary>
    /// Flattens the exception by digging on InnerException.
    /// </summary>
    /// <param name="exception">The exception.</param>
    /// <returns></returns>
    public static String FlattenException(this Exception exception)
    {
        var stringBuilder = new StringBuilder();

        while (exception != null)
        {
            stringBuilder.AppendLine(exception.Message);
            stringBuilder.AppendLine(exception.StackTrace);

            exception = exception.InnerException;
        }

        return stringBuilder.ToString();
    }

    /// <summary>
    /// Gets the first exception if this is an aggregated exception.
    /// </summary>
    /// <param name="exception">The exception.</param>
    /// <returns></returns>
    public static Exception GetFirstIfAggregate(this Exception exception)
    {
        var ex = exception as AggregateException;

        if (ex != null && ex.InnerExceptions.Count > 0)
        {
            return ex.InnerExceptions.First();
        }

        return exception;
    }

    /// <summary>
    /// Flattens the exception message in case it is an aggregated exception.
    /// </summary>
    /// <param name="exception">The exception.</param>
    /// <returns></returns>
    public static String FlattenMessage(this Exception exception)
    {
        String message = exception.Message;

        if (exception is AggregateException)
        {
            try
            {
                message = String.Join(Environment.NewLine, (exception as AggregateException).InnerExceptions.Select(x => x.FlattenMessage()));
            }
            catch { }
        }
        else if (exception.InnerException != null)
        {
            message += Environment.NewLine + exception.InnerException.FlattenMessage();
        }

        return message;
    }
}