ValueInjecter and DataTable

后端 未结 1 1220
礼貌的吻别
礼貌的吻别 2020-12-06 18:09

I was trying to figure out ValueInjecter so i can use it in our home-grown little ORM. Since i should support DataRow and DataTable mapping, i am trying to implement mapper

相关标签:
1条回答
  • 2020-12-06 18:37

    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):
    
    0 讨论(0)
提交回复
热议问题