Update 'Extensions/SqliteConnectionExtensions.cs'
This commit is contained in:
@@ -1,21 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Data.Sqlite;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
public static t Parse<t>(this object obj) {
|
namespace Extensions {}
|
||||||
|
public static t Insert<t>(this SqliteConnection cn, Dictionary<string, object> args) {
|
||||||
var r = typeof(t).GetConstructor(new System.Type[] { }).Invoke(new object[] { });
|
var r = typeof(t).GetConstructor(new System.Type[] { }).Invoke(new object[] { });
|
||||||
PropertyInfo inf = null;
|
PropertyInfo inf = null;
|
||||||
try {
|
try {
|
||||||
foreach (PropertyInfo i in r.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
|
foreach (PropertyInfo i in r.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
|
||||||
inf = i;
|
inf = i;
|
||||||
try {
|
try {
|
||||||
PropertyInfo inf2 = obj.GetType().GetProperty(inf.Name);
|
if (args.ContainsKey(inf.name)) {
|
||||||
if (inf2 != null) {
|
inf.SetValue(r, args[inf.name]);
|
||||||
inf.SetValue(r, inf2.GetValue(obj));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) { Log.Error(ex, $"Object.Parse.GetValue[{inf.Name}] failed"); }
|
} catch (Exception ex) { Log.Error(ex, $"Object.Insert.GetValue[{inf.Name}] failed"); }
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.Error(ex, $"Unable to PopulateControls with Object [Type={obj.GetType().ToString()}, PropertyInfo.Name={inf.Name}]");
|
Log.Error(ex, $"Unable to build object for SQL Insert statement [PropertyInfo.Name={inf.Name}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : Add code to Insert into Table
|
||||||
|
|
||||||
return (t)r;
|
return (t)r;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user