public T Create <T>(AbstractModel abstractModel) where T : class, new() { if (abstractModel == null) { throw new ArgumentNullException(nameof(abstractModel)); } return((T)Create(typeof(T), abstractModel)); }
private object Create(Type type, AbstractModel abstractModel) { var model = Activator.CreateInstance(type); var typeDetails = type.GetTypeDetails(); var propertyWriters = typeDetails.PropertyWriters; for (var x = 0; x < propertyWriters.Count; x++) { var writer = propertyWriters[x]; var abstractProperty = abstractModel[writer.Name]; if (abstractProperty == null) { continue; } object value; if (abstractProperty.ChildCount > 0) { value = Create(writer.PropertyType, abstractProperty); } if (abstractProperty.ValueCount > 0) { value = ChangeType(abstractProperty.Values[0], writer.PropertyType); } else { #if DEBUG // TODO?: Consider if this is okay or not throw new InvalidOperationException(); #else continue; #endif } writer.Write(model, value); } return(model); }