I have a method that is called like this
var data = new List<string>{"foo", value};
var event = MakeEvents("module", new object[]{data, "Notes:", notes, "Date:", DateTime.Now);
within MakeEvents, I break up the objectData array with a foreach look
foreach (var obj in objectData)
{
if (obj.ToString().Contains("List"))
ev.data = SerialiseData((List<string>)obj);
if (obj.GetType().ToString().Contains("System.DateTime"))
ev.date = (DateTime)obj;
if (obj.GetType().ToString().Contains("Boolean"))
ev.is_deleted = (bool)obj;
if (obj.GetType().ToString().Contains("Guid"))
ev.parent_object_id = ((Guid)obj).ToString();
if (obj.GetType().ToString() == "System.String")
{
var t = ((string)obj).Split(':').ToList();
if (t.Count == 1)
ev.notes = (string)obj;
else
{
switch (t[0])
{
case "Notes":
ev.notes = t[1];
break;
case "Updated":
ev.updated_by = t[1];
break;
case "Parent":
ev.parent_object_id = t[1];
break;
}
}
}
The issue I'm having is that the first parameter in the object is List, but it is not being recognised as such, but does give me a count of the number of objects within data.
I've tried using Enumerable.Count(obj) to get the number objects within data, but I'm given an error that I'm mixing Enumerable with IEnumerable (The type arguments for method System.Linq.Enumerable.Count(this System.Collections.Generic.IEnumerable) cannot be inferred from the usage).
Is there a simple way of obtaining the count from obj?
if obj is boolinstead of trying to match the name of the type.