2016-06-19 3 views
1

나는이 방법이 여기있는 많은 질문에 대한 답변으로 발견되는 이유를 알고 싶습니다. "KnownSourceValueInjection"에 오류가 있습니다. 또한 "GetByName (...)"이 작동하지 않는다고 말합니다 : "propertyinfo []"에는 "GetByName"에 대한 정의가 포함되어 있지 않으므로 "propertyinfo []"유형의 첫 번째 인수를 사용할 수 있습니다. 웹 서비스. 내가 사용하고 있습니다 :"KnownSourceValueInjection"의 유형 또는 이름을 찾을 수 없습니다.

  • Omu.ValueInjecter;
  • Omu.ValueInjecter.Utils;
  • Omu.ValueInjecter.Injections;

이것은 방법입니다.

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); 
      } 
     } 
    } 

답변

1

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); 
     } 
    } 
} 
관련 문제