aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs98
1 files changed, 98 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs
new file mode 100644
index 000000000..bf6b0ba0c
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+
+namespace Tango.PPC.Shared.SQL
+{
+ public class RemoteSqlRow
+ {
+ private Func<String, Object> _getFuncKey;
+ private Func<int, Object> _getFuncIndex;
+
+ public List<Object> Values { get; set; }
+
+ public RemoteSqlRow()
+ {
+ Values = new List<object>();
+ }
+
+ public Object Get(String columnName)
+ {
+ return _getFuncKey.Invoke(columnName);
+ }
+
+ public Object Get(int columnIndex)
+ {
+ return _getFuncIndex.Invoke(columnIndex);
+ }
+
+ public T Get<T>(String columnName)
+ {
+ var value = _getFuncKey.Invoke(columnName);
+
+ if (typeof(T) != value.GetType())
+ {
+ return (T)Convert.ChangeType(value, typeof(T));
+ }
+ else
+ {
+ return (T)value;
+ }
+ }
+
+ public T Get<T>(int columnIndex)
+ {
+ var value = _getFuncIndex.Invoke(columnIndex);
+
+ if (typeof(T) != value.GetType())
+ {
+ return (T)Convert.ChangeType(value, typeof(T));
+ }
+ else
+ {
+ return (T)value;
+ }
+ }
+
+ internal void Init(Func<String, Object> getFuncKey, Func<int, Object> getFuncIndex)
+ {
+ _getFuncKey = getFuncKey;
+ _getFuncIndex = getFuncIndex;
+ }
+
+ public override string ToString()
+ {
+ return String.Join(", ", Values);
+ }
+
+ public T Map<T>() where T : class, new()
+ {
+ var obj = Activator.CreateInstance<T>();
+ Map<T>(obj);
+ return obj;
+ }
+
+ public void Map<T>(T obj) where T : class
+ {
+ foreach (var prop in typeof(T).GetPropertiesWithAttribute<ColumnAttribute>())
+ {
+ try
+ {
+ var columnName = prop.GetCustomAttribute<ColumnAttribute>().Name;
+ var value = Get(columnName).ToStringSafe();
+ prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType));
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
+ }
+ }
+ }
+}