|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YAXLib
{
/// <summary>
/// Holds the list of errors occurred
/// </summary>
public class YAXParsingErrors
{
private List<KeyValuePair<YAXException, YAXExceptionTypes>> m_listExceptions = new List<KeyValuePair<YAXException, YAXExceptionTypes>>();
/// <summary>
/// Adds an exception with the corresponding type.
/// </summary>
/// <param name="ex">The exception to add.</param>
/// <param name="exType">Type of the exception added.</param>
public void AddException(YAXException ex, YAXExceptionTypes exType)
{
m_listExceptions.Add(new KeyValuePair<YAXException, YAXExceptionTypes>(ex, exType));
}
/// <summary>
/// Clears the list of errors.
/// </summary>
public void ClearErrors()
{
m_listExceptions.Clear();
}
/// <summary>
/// Adds the list of errors within another instance of <c>YAXParsingErrors</c>.
/// </summary>
/// <param name="parsingErrors">The parsing errors to add its content.</param>
public void AddRange(YAXParsingErrors parsingErrors)
{
foreach(var v in parsingErrors.m_listExceptions)
{
m_listExceptions.Add(v);
}
}
/// <summary>
/// Gets a value indicating whether the list of errors is empty or not.
/// </summary>
/// <value><c>true</c> if the list is not empty; otherwise, <c>false</c>.</value>
public bool ContainsAnyError
{
get
{
return m_listExceptions.Count > 0;
}
}
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
foreach (var pair in m_listExceptions)
{
sb.AppendLine(String.Format("{0,-8} : {1}", pair.Value, pair.Key.Message));
sb.AppendLine();
}
return sb.ToString();
}
/// <summary>
/// Gets the number of errors within the list of errors.
/// </summary>
/// <value>the number of errors within the list of errors.</value>
public int Count
{
get
{
return m_listExceptions.Count;
}
}
/// <summary>
/// Gets the the pair of Exception and its corresponding exception-type with the specified n.
/// </summary>
/// <value></value>
public KeyValuePair<YAXException, YAXExceptionTypes> this[int n]
{
get
{
return m_listExceptions[n];
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.