相关疑难解决方法(0)

ValueInjecter和DataTable

我试图找出ValueInjecter,所以我可以在我们自己种植的小ORM中使用它.由于我应该支持DataRow和DataTable映射,我正在尝试为这种类型实现映射器.老实说,文档不够好,我想给它一个机会.也许Omu或该图书馆的其他一些用户会回答.

这是我的DataRow注入器

public class DataRowInjection: KnownSourceValueInjection<DataRow>
    {
        protected override void Inject(DataRow source, object target)
        {
            for (var i = 0; i < source.ItemArray.Count(); i++)
            {

                //TODO: Read from attributes or target type
                var activeTarget = target.GetProps().GetByName(source.Table.Columns[i].ToString(), true);
                if (activeTarget == null) continue;

                var value = source.ItemArray[i];
                if (value == DBNull.Value) continue;

                activeTarget.SetValue(target, value);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

这非常有效.所以这里有一个问题我如何为DataTable实现这个并返回Ienumarable或IList.我期望做的代码片段就像.

public class DataTableInjector  : ?????
    {
        protected override void Inject(DataTable source, IList<T> target)   where T : class
        {

          // Do My Staff
            foreach …
Run Code Online (Sandbox Code Playgroud)

c# automapper valueinjecter

9
推荐指数
1
解决办法
2800
查看次数

标签 统计

automapper ×1

c# ×1

valueinjecter ×1