ValueInjecter and DataTable

孤者浪人 提交于 2019-11-28 01:03:17
Omu

Same as you did it for DataRow, you just use KnownSourceValueInjection<DataTable> now.

Also as you can see the Inject method is void so you don't return anything you just change the target object (which already exists).

Remember that InjectFrom doesn't create new objects, it injects values into an existing one.

So you are going to have:

var list = new List<T>();
list.InjectFrom<MyFromDataTableInj>(dataTable)

Actually in your case you are going to use this injection only from DataTable to IList<T> so you could do like this:

   public class My<T> : ValueInjection
   {
        protected override void Inject(object source, object target)
        {
            var dt = source as DataTable;
            var t = target as IList<T>;
... 
        }
    }

And usage:

list.InjectFrom<My<Foo>>(datatable):
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!