|
@@ -67,7 +67,17 @@ namespace InABox.Core
|
|
|
Set(columnName, value);
|
|
|
}
|
|
|
|
|
|
- public void FillObject(Type t, BaseObject obj)
|
|
|
+ /// <summary>
|
|
|
+ /// Fill an object with the data from this row.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// If <paramref name="overrideExisting"/> is <see langword="true"/>, then the data in the row will override the data in <paramref name="obj"/>,
|
|
|
+ /// even if that column has previously been loaded (i.e., it is in <see cref="BaseObject.LoadedColumns"/>).
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="t">The type of <paramref name="obj"/>.</param>
|
|
|
+ /// <param name="obj">The object to fill.</param>
|
|
|
+ /// <param name="overrideExisting">Override any data which already exists in <paramref name="obj"/>.</param>
|
|
|
+ public void FillObject(Type t, BaseObject obj, bool overrideExisting = false)
|
|
|
{
|
|
|
obj.SetObserving(false);
|
|
|
|
|
@@ -85,19 +95,20 @@ namespace InABox.Core
|
|
|
var value = this[column];
|
|
|
try
|
|
|
{
|
|
|
- if (bFirst)
|
|
|
+ if (obj.LoadedColumns.Add(column) || overrideExisting)
|
|
|
{
|
|
|
- var prop = DatabaseSchema.Property(t, column);
|
|
|
- setters.Add(prop?.Setter());
|
|
|
+ if (bFirst)
|
|
|
+ {
|
|
|
+ var prop = DatabaseSchema.Property(t, column);
|
|
|
+ setters.Add(prop?.Setter());
|
|
|
+ }
|
|
|
+
|
|
|
+ var setter = setters[i];
|
|
|
+ if (setter != null && value != null)
|
|
|
+ setter.Invoke(obj, value);
|
|
|
+ else
|
|
|
+ CoreUtils.SetPropertyValue(obj, column, value);
|
|
|
}
|
|
|
-
|
|
|
- var setter = setters[i];
|
|
|
- if (setter != null && value != null)
|
|
|
- setter.Invoke(obj, value);
|
|
|
- else
|
|
|
- CoreUtils.SetPropertyValue(obj, column, value);
|
|
|
-
|
|
|
- obj.LoadedColumns.Add(column);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -109,15 +120,24 @@ namespace InABox.Core
|
|
|
obj.SetObserving(true);
|
|
|
}
|
|
|
|
|
|
- public void FillObject<T>(T obj) where T : BaseObject
|
|
|
+ /// <summary>
|
|
|
+ /// Fill an object with the data from this row.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// If <paramref name="overrideExisting"/> is <see langword="true"/>, then the data in the row will override the data in <paramref name="obj"/>,
|
|
|
+ /// even if that column has previously been loaded (i.e., it is in <see cref="BaseObject.LoadedColumns"/>).
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="obj">The object to fill.</param>
|
|
|
+ /// <param name="overrideExisting">Override any data which already exists in <paramref name="obj"/>.</param>
|
|
|
+ public void FillObject<T>(T obj, bool overrideExisting = false) where T : BaseObject
|
|
|
{
|
|
|
- FillObject(typeof(T), obj);
|
|
|
+ FillObject(typeof(T), obj, overrideExisting: overrideExisting);
|
|
|
}
|
|
|
|
|
|
public BaseObject ToObject(Type t)
|
|
|
{
|
|
|
var entity = (Activator.CreateInstance(t) as BaseObject)!;
|
|
|
- FillObject(t, entity);
|
|
|
+ FillObject(t, entity, overrideExisting: true);
|
|
|
return entity;
|
|
|
}
|
|
|
|