static StringBuilder ToText(IConfigNode val, int level, StringBuilder output) { var map = val.GetProperties(); foreach (var item in map) { ToText(item.Value, item.Key, level + 1, output); } return(output); }
private static object DeserializeObject(object target, IConfigNode configNode) { var targetType = target.GetType(); var propertyValues = configNode.GetProperties(); var accessor = ClassAccessorRepository.GetClassAccessor(target, AccessorType.Reflection); var persistProperties = targetType.GetPersistProperties(AccessorType.Reflection); var targetProperties = new Dictionary <string, Type>(persistProperties.Count); foreach (var item in persistProperties) { targetProperties.Add(item.Key.ToLower(), item.Value); } foreach (var pair in propertyValues) { var pName = pair.Key; var pValue = pair.Value; var propertyName = string.Empty; var pType = TryGetPropertyType(targetProperties, pName, out propertyName); if (pType == null) { continue; } var targetValue = accessor.GetValue(target, propertyName); if (pType.IsListType()) { var targetList = targetValue as IList; if (targetList == null) { targetList = (IList)pType.BuildObject(); accessor.SetValue(target, propertyName, targetList); } IList valList = null; if (pValue is IList) { valList = (IList)pValue; } else { valList = new List <object>(1) { pValue }; } DeserializeList(pType, targetList, valList); } else if (pType.IsDictionaryType()) { var targetMap = targetValue as IDictionary; if (targetMap == null) { targetMap = (IDictionary)pType.BuildObject(); accessor.SetValue(target, propertyName, targetMap); } var valMap = configNode.GetNodeMap(pName); DeserializeDictionary(pType, targetMap, valMap); } else { if (pValue is IConfigNode) { var val = BuildObject(pType, (IConfigNode)pValue); accessor.SetValue(target, propertyName, val); } else { var val = DeserializePrimitiveValue(pValue, pType); accessor.SetValue(target, propertyName, val); } } } return(target); }