private static void ProcessObject(object obj, string path, IDictionary <String, EntityProperty> entities) { obj.GetType().GetProperties().Where(propertInfo => propertInfo.CanRead && propertInfo.CanWrite).ToList().ForEach(propertyInfo => { string id = propertyInfo.Name; object value = propertyInfo.GetValue(obj, index: null); if (value != null) { IConverter converter = ConveterFactory.FindConverter(value.GetType()); if (converter == null) { if (value.GetType().IsValueType) { throw new ConverterException("No convertor found for: " + id + " / " + propertyInfo.GetType().ToString()); } else { ProcessObject(value, BuildEntityName(path, id), entities); } } else { EntityProperty ep = converter.GetValue(propertyInfo.GetType(), propertyInfo.GetValue(obj)); entities.Add(BuildEntityName(path, id), ep); } } }); }
private static void ProcessObject(object obj, string path, IDictionary <String, EntityProperty> entities) { obj.GetType().GetProperties().Where(propertyInfo => propertyInfo.CanRead && propertyInfo.CanWrite).ToList().ForEach(propertyInfo => { string id = propertyInfo.Name; string entityName = BuildEntityName(path, id); if (entities.ContainsKey(entityName)) { Type pType = propertyInfo.PropertyType; IConverter converter = ConveterFactory.FindConverter(pType); if (converter != null) { propertyInfo.SetValue(obj, converter.BuildValue(entities[entityName], pType), index: null); } else { if (pType.IsValueType) { throw new ConverterException("No convertor found for: " + id + " / " + pType.ToString()); } object child = FormatterServices.GetUninitializedObject(pType); ProcessObject(child, id, entities); } } }); }