-
Notifications
You must be signed in to change notification settings - Fork 1
/
CircularAssemblyReferenceException.cs
50 lines (46 loc) · 1.42 KB
/
CircularAssemblyReferenceException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Text;
namespace SolGen
{
/// <summary>
/// Exception thrown when a circular reference is detected
/// </summary>
internal class CircularAssemblyReferenceException : Exception
{
private readonly IEnumerable<string> _assemblyStack;
/// <summary>
/// Constructor
/// </summary>
/// <param name="assemblyStack">stack of assembly dependencies</param>
public CircularAssemblyReferenceException(IEnumerable<string> assemblyStack)
{
_assemblyStack = assemblyStack ?? new List<string>();
}
/// <summary>
/// Gets a message that describes the current exception.
/// </summary>
/// <returns>
/// The error message that explains the reason for the exception, or an empty string("").
/// </returns>
public override string Message
{
get { return FormatStack(); }
}
private string FormatStack()
{
var sb = new StringBuilder("Circular reference:\n");
var level = 1;
foreach (var assembly in _assemblyStack)
{
for (int i = 0; i < level; i++)
{
sb.Append("\t");
}
sb.AppendLine(assembly);
level++;
}
return sb.ToString();
}
}
}