제 질문은이 코드를 리팩토링하고 싶습니다. , RemainingTimeHours
및 InitialEffortEstimateHours
은 nullable double (double?), 인 값을 검색해야합니다.이 값은 캐시 (사전)에서 가져와야하며 캐시에서 없으면 db (저장소 패턴)에서 가져와야합니다.GetProperty에서 getValue를 사용하는 방법은 작업 결과에서 반환했습니다. <T>
사전의 값이 잘 작동합니다. 문제는 리포지토리에서 값을 가져 와서 리플렉션을 사용하는 것입니다. FindFirstOrDefaultAsync 객체의 Task<T>
USTask
public partial class USTask
{
public long Aid { get; set; }
public Nullable<double> RemainingTimeHours { get; set; }
public Nullable<double> SpentTimeHours { get; set; }
public Nullable<double> InitialEffortEstimateHours { get; set; }
}
클래스를 반환 KpiService KpiVieModel.cs
나는 생성자에서 kpiService를 주입하고,이 같은 전화에
public double GetEstimatedStoryPoint(
List<CrossReference> result,
string propertyName,
string pattern,
long Aid,
bool isCache,
bool isUserStory = false)
{
if (!isCache)
{
double? value = 0;
//ERROR -
value = _userStoryTaskRepository
.FindFirstOrDefaultAsync(id => id.Aid == ids.Aid)
.Result
.GetType()
.GetProperty(propertyName)
.GetValue(value , null) as double?;
}
else
{
//Working fine
value = GetValuesForEstimatedStoryPoint(GraphTable._USTask, propertyName, ids.Aid);
}
......
, 매개 변수로 3 propertyName을 전달합니다. SpentTimeHours
, RemainingTimeHours
, InitialEffortEstimateHours
은 내가 문제는 대상 소스의 유형과 일치하지 않는 객체 인이
// This Work
//In cache
sumSpentTime += _kpiService.GetEstimatedStoryPoint(crosReferenceInCache, "SpentTimeHours", pattern, Aid, true, isUserStory);
sumRemainigTime += _kpiService.GetEstimatedStoryPoint(crosReferenceInCache, "RemainingTimeHours", pattern, Aid, true, isUserStory);
sumEstimated += _kpiService.GetEstimatedStoryPoint(crosReferenceInCache, "InitialEffortEstimateHours", pattern, Aid, true, isUserStory);
This not..
//not in cache , db access
sumSpentTime += _kpiService.GetEstimatedStoryPoint(crosReferenceNotInCache, "SpentTimeHours", pattern, Aid, false, isUserStory);
sumRemainigTime += _kpiService.GetEstimatedStoryPoint(crosReferenceNotInCache, "RemainingTimeHours", pattern, Aid, false, isUserStory);
sumEstimated += _kpiService.GetEstimatedStoryPoint(crosReferenceNotInCache, "InitialEffortEstimateHours", pattern, Aid, false, isUserStory);
처럼 호출합니다.
이 작업을 n 번하고 싶지 않습니다.
SpentTimeHours = _userStoryTaskRepository.FindFirstOrDefaultAsync(id => id.Aid == ids.Aid).Result.SpentTimeHours;
RemainingTimeHours = _userStoryTaskRepository.FindFirstOrDefaultAsync(id => id.Aid == ids.Aid).Result.RemainingTimeHours;
InitialEffortEstimateHours = _userStoryTaskRepository.FindFirstOrDefaultAsync(id => id.Aid == ids.Aid).Result.InitialEffortEstimateHours;
'foundA' 무엇입니까? 'Result'에 변수를 할당하고'GetValue'에 그것을 넘겨 줄 필요가 없습니까? – Quantic
안녕하세요 Quantic, 죄송합니다, 복사 및 붙여 넣기가 잘못되었습니다, FoundA, 존재하지 않습니다. 결과 값을 변수 값에 전달해야합니다. – jolynice
2 단계가되어야합니다. 저는 꽤 확신합니다 :'var myObject = _userStoryTaskRepository.FindFirstOrDefaultAsync (id => id.Aid == ids.Aid) .Result; value = myObject.GetType(). GetProperty (propertyName) .GetValue (myObject, null) double?; ' – Quantic