/// <summary> Non-generic version of SaveAsObject. You probably want to use SaveAsObject. </summary> /// <param name="type"> what type to save this object as </param> /// <param name="savethis"> the object to save </param> public void SaveAsObjectNonGeneric(Type type, object savethis) { bool _autosave = AutoSave; AutoSave = false; // don't write to disk when we don't have to try { foreach (var f in ComplexTypes.GetValidFields(type)) { SetNonGeneric(f.FieldType, f.Name, f.GetValue(savethis)); } foreach (var p in ComplexTypes.GetValidProperties(type)) { SetNonGeneric(p.PropertyType, p.Name, p.GetValue(savethis)); } } finally { AutoSave = _autosave; } if (AutoSave) { SaveAllData(); } }
/// <summary> Non-generic version of GetAsObject. You probably wantto use GetAsObject. </summary> /// <param name="type"> the type to get this object as </param> public object GetAsObjectNonGeneric(Type type) { object returnThis = Activator.CreateInstance(type); foreach (var f in ComplexTypes.GetValidFields(type)) { var value = GetNonGeneric(f.FieldType, f.Name, f.GetValue(returnThis)); f.SetValue(returnThis, value); } foreach (var p in ComplexTypes.GetValidProperties(type)) { var value = GetNonGeneric(p.PropertyType, p.Name, p.GetValue(returnThis)); p.SetValue(returnThis, value); } return(returnThis); }