bool InstantiateSection(dynamic dataDict, Tuple<string, string> when_id) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; mLogger.Log(methodName, "", 3); bool success = true; Section section = new Section(); SectionTerm term = new SectionTerm(); List<string> studentList = new List<string>(); // Get each dp (datapoint) found in dataDict foreach (KeyValuePair<string, dynamic> dpParent in dataDict) { if (dpParent.Value != null) { Type valueType = dpParent.Value.GetType(); if (valueType.IsGenericType) { // This value item is not just another string value but (probably) another dictionary Type baseType = valueType.GetGenericTypeDefinition(); if (baseType == typeof(Dictionary<,>)) { mLogger.Log(methodName, string.Format("Getting data for Key: {0}", dpParent.Key), 3); foreach (KeyValuePair<string, dynamic> dpChild in dpParent.Value) { mLogger.Log(methodName, string.Format("Key: {0} Value: {1}", dpChild.Key, dpChild.Value), 3); if (dpParent.Key == "term") { PropertyInfo pi = term.GetType().GetProperty(dpChild.Key); ValidateClassProperty(pi, dpChild.Key, "SectionTerm"); pi.SetValue(term, Convert.ChangeType(dpChild.Value, pi.PropertyType), null); } } } } else if (valueType == typeof(ArrayList)) { if (dpParent.Key == "students") { foreach (string student in dpParent.Value) { studentList.Add(student); } } } else if (valueType.Name == "String") { mLogger.Log(methodName, string.Format("Key: {0} Value: {1}", dpParent.Key, dpParent.Value), 3); PropertyInfo pi = section.GetType().GetProperty(dpParent.Key); ValidateClassProperty(pi, dpParent.Key, "Section"); pi.SetValue(section, Convert.ChangeType(dpParent.Value, pi.PropertyType), null); } } } // check whether we are instantiating for event data and if so, set event_type and id if (when_id.Item1 == "current_attributes") { section.event_type = when_id.Item1; } else if (when_id.Item1 == "previous_attributes") { section.event_type = when_id.Item1; section.id = when_id.Item2; } section.term = term; section.students = studentList; mWrappedData.Sections.Add(section); return success; }
bool InstantiateSection(dynamic dataDict, Tuple <string, string> when_id) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; mLogger.Log(methodName, "", 3); bool success = true; Section section = new Section(); SectionTerm term = new SectionTerm(); List <string> studentList = new List <string>(); // Get each dp (datapoint) found in dataDict foreach (KeyValuePair <string, dynamic> dpParent in dataDict) { if (dpParent.Value != null) { Type valueType = dpParent.Value.GetType(); if (valueType.IsGenericType) { // This value item is not just another string value but (probably) another dictionary Type baseType = valueType.GetGenericTypeDefinition(); if (baseType == typeof(Dictionary <,>)) { mLogger.Log(methodName, string.Format("Getting data for Key: {0}", dpParent.Key), 3); foreach (KeyValuePair <string, dynamic> dpChild in dpParent.Value) { mLogger.Log(methodName, string.Format("Key: {0} Value: {1}", dpChild.Key, dpChild.Value), 3); if (dpParent.Key == "term") { PropertyInfo pi = term.GetType().GetProperty(dpChild.Key); ValidateClassProperty(pi, dpChild.Key, "SectionTerm"); pi.SetValue(term, Convert.ChangeType(dpChild.Value, pi.PropertyType), null); } } } } else if (valueType == typeof(ArrayList)) { if (dpParent.Key == "students") { foreach (string student in dpParent.Value) { studentList.Add(student); } } } else if (valueType.Name == "String") { mLogger.Log(methodName, string.Format("Key: {0} Value: {1}", dpParent.Key, dpParent.Value), 3); PropertyInfo pi = section.GetType().GetProperty(dpParent.Key); ValidateClassProperty(pi, dpParent.Key, "Section"); pi.SetValue(section, Convert.ChangeType(dpParent.Value, pi.PropertyType), null); } } } // check whether we are instantiating for event data and if so, set event_type and id if (when_id.Item1 == "current_attributes") { section.event_type = when_id.Item1; } else if (when_id.Item1 == "previous_attributes") { section.event_type = when_id.Item1; section.id = when_id.Item2; } section.term = term; section.students = studentList; mWrappedData.Sections.Add(section); return(success); }