c# - ValueInjecter and DataTable -


I was trying to find ValueInjecter so that I can use it in small ORM developed in our home. Since I should support Datarov and DataTable Mapping, I am trying to implement these types of mappers. And honestly the documentation is not good enough and I wanted to give it a shot. Maybe Omu or some other users of this library will reply.

Here is my Detroit Injector

  Public class DataRowInjection: KnownSourceValueInjection & lt; DataRow & gt; {Safe Override Zero Inject (Detorro Source, Object Target) {for (var i = 0; i & lt; source.ItemArray.Count (); i ++) {// TODO: attributes or target type var with active target = Target.GetProps () .GetByName (source.Table.Columns [i] .ostring (), true); If (activeTarget == zero) will continue; Var Value = source.ItemArray [i]; If (value == DBNull.Value) continues; ActiveTarget.SetValue (target, value); }}}   

This works very well, so here is the question of how I can implement it for datatable and Ienumarable or IList can return. The code snippet is what I expected to do.

  public class DataTableInjector: ????? {Safe Override Zero Inject (Datatyal Sources, ILIIT & lt; T & gt; Goals) where T: Class {// Due My Staff Fourresh (different rows in source ROS) {target [i]. Inject Form & lt; Detrovert injection & gt; (Line); } // return IList? }}   

How can I complete this Thanksgiving

~~~~~~ Here is the complete code written with the help of Omu

  public class data tab injection & lt; T & gt; : ValueInjection where T: new () source for safe override zero injection (object source, object target) {var dt = DataTable; Var t = Target as IList & lt; T & gt; Foreign (Detroor DR in D.T.RO) {var t2 = new T (); T2.InjectFrom & LT; DataRowInjection & gt; (Dr.); T.Add (t2); }}}}    

In the same way as you did it DataRow , You could just click the knownSourceValice injection & lt; DataTable & gt; .

With this, you can see inject method zero so that you do not return anything you just target object (which already exists) Change.

Remember that InjectFrom does not create new objects, it injects any one current value. / P>

Then you are going:

  var list = new list & lt; T & gt; (); In fact, in this case, this injection will be used only from Datatelle to  IList & lt; T & gt; , so that you can do it. By the way:  
  Public category My < T & gt; : ValueInjection {Safe Override Zero Injection (Object Source, Object Target) {var dt = DataTable as Source; Var t = Target as IList & lt; T & gt; ...}}   

and use:

  list.InjectFrom & lt; My & lt; Foo & gt; & Gt; (Datasell):    

Comments