I've created a class witch contains a typed list and derives to another class I created. This looks as follows:
namespace MyIntegretyCheck.Common
{
/// <summary>
/// Description of PolicyErrors.
/// </summary>
public partial class PolicyErrorEndingDates
{
public int ID_P {get;set;}
public DateTime DT_S_E {get;set;}
public DateTime DT_SC_E {get;set;}
public List<PolicyErrorDescr> Errors {get;set;}
}
public partial class PolicyErrorDescr
{
public string Field1{get;set;}
public string Field2 {get;set;}
public string F1IsThanF2 {get;set;}
public string Message {get;set;}
public int ErrorLevel {get;set;} //0= Info | 1= Warning | 2= Error
}
}
well now I created a typed list of PolicyErrorEndingDates, added a entry and tried then to add entries of his nested list Errors. As follows:
public List<PolicyErrorEndingDates> MyPolicyEndingDates()
{
DAL.PolicyEndingDates ped = new DAL.PolicyEndingDates();
List<PolicyErrorEndingDates> MyErrors = new List<PolicyErrorEndingDates>();
foreach(var m in ped.CheckTables())
{
bool HasError = false;
PolicyErrorEndingDates p = new PolicyErrorEndingDates();
p.ID_P = m.ID_P;
if(m.DT_S_E != m.DT_SC_E)
{
PolicyErrorDescr e = new PolicyErrorDescr();
HasError = true;
e.Field1 = "DT_S_E";
e.Field2 = "DT_SC_E";
e.Message = "blablabla...";
e.ErrorLevel = 3;
p.Errors.Add(e);
}
if(HasError)
MyErrors.Add(p);
}
}
But the Debugger creashed with the message "Object reference not set to an instance of an object", at the Line "p.Errors.Add(e);" inside my "if". what did I wrong? How can I create a instance of the nested list?
Tanks in Advance Johannes