public static void AppendProperties(XmlValue innerProc, object item) { foreach (var innerProp in item.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(ExportableAttribute), false).Any(x => ((ExportableAttribute)x).PropertyType == ExportType.Regular))) { if (innerProp.Name == "RoleId") { if (innerProp.GetValue(item, null) == null) continue; var id = SafeTypeConverter.Convert<int>(innerProp.GetValue(item, null)); if (!_rolelist.Contains(id)) _rolelist.Add(id); } if (innerProp.Name == "RoleIds") { var val = innerProp.GetValue(item, null).ToString(); if (string.IsNullOrEmpty(val)) continue; foreach (var intId in val.Split(',').Select(SafeTypeConverter.Convert<int>).Where(intId => !_rolelist.Contains(intId))) { _rolelist.Add(intId); } } if (innerProp.Name == "BusinessUnitId") { if (innerProp.GetValue(item, null) == null) continue; var id = SafeTypeConverter.Convert<int>(innerProp.GetValue(item, null)); if (!_bulist.Contains(id)) _bulist.Add(id); } var innerList = new XmlValue { Name = innerProp.Name, Value = innerProp.GetValue(item, null) != null ? innerProp.GetValue(item, null).ToString() : "Null" }; if (innerProc.ChildValuesList == null) innerProc.ChildValuesList = new List<XmlValue>(); innerProc.ChildValuesList.Add(innerList); } foreach (var innerProp in item.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(ExportableAttribute), false).Any(x => ((ExportableAttribute)x).PropertyType == ExportType.Convertible))) { var value = innerProp.GetValue(item, null); var customAttributeData = innerProp.GetCustomAttributesData().FirstOrDefault(x => x.AttributeType == typeof(ExportableAttribute)); object innerValue = null; if (customAttributeData != null) { try { innerValue = value != null ? value.GetType().GetProperty(customAttributeData.ConstructorArguments[1].Value.ToString()).GetValue(value) : null; } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Export Process", ex); } } var innerList = new XmlValue { Name = innerProp.Name, Value = innerValue != null ? innerValue.ToString() : "Null" }; if (innerProc.ChildValuesList == null) innerProc.ChildValuesList = new List<XmlValue>(); innerProc.ChildValuesList.Add(innerList); } foreach (var innerProp in item.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(ExportableAttribute), false).Any(x => ((ExportableAttribute)x).PropertyType == ExportType.Expandable))) { var innerList = new XmlValue(); try { FillListProperty(innerProp, innerList, item); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Export Process", ex); } if (innerProc.ChildValuesList == null) innerProc.ChildValuesList = new List<XmlValue>(); innerProc.ChildValuesList.Add(innerList); } foreach (var innerProp in item.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(ExportableAttribute), false).Any(x => ((ExportableAttribute)x).PropertyType == ExportType.Resolvable))) { var innerList = new XmlValue { Name = innerProp.Name }; var innerVal = innerProp.GetValue(item, null); if (innerVal == null) continue; try { AppendProperties(innerList, innerVal); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Export Process", ex); } if (innerProc.ChildValuesList == null) innerProc.ChildValuesList = new List<XmlValue>(); innerProc.ChildValuesList.Add(innerList); } }
private static void FillListProperty(PropertyInfo prop, XmlValue innerProc, object process) { innerProc.Name = prop.Name; innerProc.ChildValuesList = new List<XmlValue>(); var itemList = prop.GetValue(process, null) as IList; if (itemList == null) return; foreach (var item in itemList) { if (prop.Name == "SectionList" && item.GetType().GetProperty("IsBase") != null && item.GetType().GetProperty("IsBase").GetValue(item, null).ToString() == "True") continue; var innerList = new XmlValue(); innerList.Name = prop.Name.EndsWith("List") ? prop.Name.Remove(prop.Name.Length - 4) : (prop.Name.EndsWith("s") ? prop.Name.Remove(prop.Name.Length - 1) : prop.Name); innerList.AttributesList = item.GetType().GetProperties().Any(x => x.Name == "StepId") ? new List<XmlAttribute> { new XmlAttribute { Name = "StepId", Value = item.GetType().GetProperty("StepId").GetValue(item, null).ToString() } } : (item.GetType().GetProperties().Any(x => x.Name == "Id") ? new List<XmlAttribute> { new XmlAttribute { Name = "Id", Value = item.GetType().GetProperty("Id").GetValue(item, null).ToString() } } : null); AppendProperties(innerList, item); innerProc.ChildValuesList.Add(innerList); } }