public static void ConvertToIPost(object input, IPostModel model) { var type = input.GetType().GetRealType(); model.FullType = type.FullName; model.ThisAssembly = type.Assembly.FullName; int lang = 0; long modelId = 0; if (model is ContentPostModel) { (model as ContentPostModel).ViewPath = type.Name; lang = (input as IContentModel).Lang; } modelId = (input as IInt64Key).Id; var resultProperty = model.GetType().GetRealType().GetProperties().Where(b => b.BaseProperty()).ToList(); var properties = input.GetType().GetRealType().GetProperties(); foreach (var p in properties) { if (p.SkippedProperty()) { continue; } if (p.BaseProperty()) { var baseP = resultProperty.Where(b => b.Name == p.Name).FirstOrDefault(); if (baseP == null) { continue; } var inputValue = p.GetValue(input); if (inputValue == null) { continue; } baseP.SetValue(model, inputValue); continue; } var prop = p.GetContentPropertyByPropertyInfo(input, lang, modelId); if (prop == null) { continue; } model.Properties.Add(prop); } model.Properties = model.Properties.OrderByDescending(b => b.SortOrder).ToList(); }
public static object ConvertToBaseModel(this IPostModel input, object result, bool deleteExistFile = true, List <string> oldFiles = null, List <string> newFiles = null) { var type = input.FullType; var asm = input.ThisAssembly; var properties = result.GetType().GetRealType().GetProperties(); var baseProperty = input.GetType().GetRealType().GetProperties().Where(b => b.BaseProperty()).ToList(); foreach (var p in properties) { try { if (p.BaseProperty()) { var inputBaseProperty = baseProperty.Where(b => b.Name == p.Name).FirstOrDefault(); if (inputBaseProperty == null) { continue; } p.SetValue(result, inputBaseProperty.GetValue(input)); continue; } if (p.SkippedProperty()) { continue; } p.SetPropertyValue(input, result, deleteExistFile, oldFiles, newFiles); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(result); }