找不到类型或名称 "KnownSourceValueInjection"

The type or name "KnownSourceValueInjection" could not be found

我想知道为什么这个方法在这里找到许多问题的答案不起作用,"KnownSourceValueInjection" 中有错误。另外 "GetByName(...)" 不工作,它说: "propertyinfo[]" 不包含 "GetByName" 接受类型 "propertyinfo[]" 的第一个参数的定义可能 found.I 正在工作在网络服务上。 我正在使用:

这就是方法。

    public class ReaderInjection : KnownSourceValueInjection<IDataReader>
    {
        protected override void Inject(IDataReader source, object target)
        {
            for (var i = 0; i < source.FieldCount; i++)
            {
                var activeTarget = target.GetProps().GetByName(source.GetName(i), true);
                if (activeTarget == null) continue;

                var value = source.GetValue(i);
                if (value == DBNull.Value) continue;

                activeTarget.SetValue(target, value);
            }
        }
    }

使用KnownSourceInjection,新版本重命名;对于 ReaderInjection,请参阅来源 here

public class ReaderInjection : KnownSourceInjection<IDataReader>
{
    protected override void Inject(IDataReader source, object target)
    {
        for (var i = 0; i < source.FieldCount; i++)
        {
            var trgProp = target.GetType().GetProperty(source.GetName(i), BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (trgProp == null) continue;

            var value = source.GetValue(i);
            if (value == DBNull.Value) continue;

            trgProp.SetValue(target, value);
        }
    }
}