diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-08-03 12:33:07 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-08-03 12:33:07 +0300 |
| commit | d52aaaeb7e732d131146b68a81aa672d9f5f8732 (patch) | |
| tree | 04e161f1c1f3ffe55ebc07682c29da5cf2861717 /Software/Visual_Studio/PPC/Tango.PPC.Shared/SQL/RemoteSqlRow.cs | |
| parent | d2102fd617527a3dc66b6cfdde8db6eb99d1a3eb (diff) | |
| parent | f2a27972ca652ef568e5eede22d86f9698a08cca (diff) | |
| download | Tango-d52aaaeb7e732d131146b68a81aa672d9f5f8732.tar.gz Tango-d52aaaeb7e732d131146b68a81aa672d9f5f8732.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
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.cs | 98 |
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); + } + } + } + } +} |
