Don't use Arraylist. That is not the same as a List<object>.
There are a lot of resources on the web for this. Fortunate for you, I just went through this so it is fresh in my mind. The first thing you need to do is create the list class. Here's the code I'm currently working with. Note there is one overload (two classes with the same name and different parameters):
public class Contexts
{
public string contextType;
public object startDate;
public object endDate;
public string name;
public string heading;
public int period;
public Contexts(string contextType, object endDate, string name, string heading, int period)
{
this.contextType = contextType;
this.endDate = endDate;
this.name = name;
this.heading = heading;
this.period = period;
}
public Contexts(string contextType, object startDate, object endDate, string name, string heading, int period)
{
this.contextType = contextType;
this.startDate = startDate;
this.endDate = endDate;
this.name = name;
this.heading = heading;
this.period = period;
}
}
Note that 'startDate' and 'endDate' are objects. The cool thing about lists is that you can put ANYTHING in them.
Here is the method that uses the list. The 'ListContexts' method has an output type of List<Contexts>:
List<Contexts> lst = ListContexts(dtsInstance, aConnection);
Here is the ListContexts method:
public static List<Contexts> ListContexts(XmlDocument dtsInstance, OleDbConnection aConnection)
{
List<Contexts> ctx = new List<Contexts>();
XmlNodeList contextList = dtsInstance.GetElementsByTagName("xbrli:context");
foreach (XmlElement contextElm in contextList)
{
string contextID = contextElm.GetAttribute("id");
XmlElement xbrliEntity = contextElm["xbrli:entity"];
XmlElement xbrliPeriod = contextElm["xbrli

eriod"];
XmlElement CIK = xbrliEntity["xbrli:identifier"];
XmlElement instant = xbrliPeriod["xbrli:instant"];
XmlElement startDate = xbrliPeriod["xbrli:startDate"];
XmlElement endDate = xbrliPeriod["xbrli:endDate"];
string cikValue = CIK.InnerText;
string startDateValue = "Null";
string endDateValue = "Null";
string instantValue = "Null";
string periodValue = "";
string heading = "heading";
DateTime startDateDate = new DateTime();
DateTime endDateDate = new DateTime();
DateTime instantDate = new DateTime();
DateTime dt;
//List<Contexts> ctx = new List<Contexts>();
if (instant != null)
{
instantValue = instant.InnerText;
periodValue = "instance";
dt = DateTime.ParseExact(instantValue, "yyyy-MM-dd", null);
instantValue = "'" + dt.ToShortDateString() + "'";
instantDate = dt;
heading = instantDate.ToString("MM/dd/yyyy");
ctx.Add(new Contexts(periodValue,instantDate,contextID,heading,100));
}
else
{
startDateValue = startDate.InnerText;
dt = DateTime.ParseExact(startDateValue, "yyyy-MM-dd", null);
startDateValue = "'" + dt.ToShortDateString() + "'";
startDateDate = dt;
endDateValue = endDate.InnerText;
dt = DateTime.ParseExact(endDateValue, "yyyy-MM-dd", null);
endDateValue = "'" + dt.ToShortDateString() + "'";
endDateDate = dt;
TimeSpan span = endDateDate - startDateDate;
string monthDuration = Math.Round((double)span.Days / 30).ToString();
heading = monthDuration + " Months Ending " + endDateDate.ToString("MM/dd/yyyy");
periodValue = "duration";
ctx.Add(new Contexts(periodValue,startDateDate,endDateDate,contextID, heading, Convert.ToInt16(monthDuration)));
}
}
//return ctx.Sort(delegate (ctx c1, ctx c2));
return ctx;
}
It might look like there's a lot going on here, but there isn't really. Once you set them up, lists can be very powerful.