Hello RaGEZONE,
This class will make Casting from the Database more easily!
(not tested yet)
Why superior?
- Doesn't need to cast and parse objects.
How to use?Code:using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Atomy.Adapters { public class RowAdapter : IDisposable { public volatile DataRow Row; private int RowListenCounter; public RowAdapter(DataRow Row) { this.Row = Row; this.RowListenCounter = default(int); } public DataColumn GetColumn(string Name) { DataColumn Output = Row.Table.Columns.Cast<DataColumn>().SingleOrDefault(column => column.ColumnName.ToLower().Equals(Name.ToLower())); return Output; } public T Item<T>(string ColumnName) { try { return Row.Field<T>(ColumnName); } catch { return default(T); } } public T Item<T>(int ColumnIndex) { try { return Row.Field<T>(0); } catch { return default(T); } } public T MoveNext<T>() { return Item<T>(Interlocked.Increment(ref RowListenCounter)); } public void Dispose() { GC.SuppressFinalize(this); } } }
Code:using (RowAdapter Adapter = new RowAdapter(CharacterRow)) { Character.Id = Adapter.Item<Guid>("id"); Character.Username = Adapter.Item<string>("username"); Character.Credits = Adapter.Item<int>("credits"); }


Reply With Quote

