User-313978683 posted
This is the current implementation for the fix. Is there a better way I could have done this?
public class ContextErrorCollection
{
public static void AddToErrorCollection(string error)
{
var nsec = ErrorCollection;
nsec.Add(error);
ErrorCollection = nsec;
}
public static List<string> ErrorCollection
{
get
{
var nsec = HttpContext.Current.Items["ErrorCollection"] as NonStaticErrorCollection ?? new NonStaticErrorCollection();
return nsec.ItemList;
}
set
{
var nsec = new NonStaticErrorCollection();
foreach (string error in value)
{
nsec.ItemList.Add(error);
}
HttpContext.Current.Items["ErrorCollection"] = nsec;
}
}
}
public class NonStaticErrorCollection
{
public string[] list()
{
return m_sList.ToArray();
}
public List<string> ItemList
{
get
{
if (m_sList == null) return new List<string>();
return m_sList;
}
}
private readonly List<string> m_sList = new List<string>();
}
//Calling Code
ContextErrorCollection.AddToErrorCollection(string.Format("Adding error number {0} to list...", i));