0
我怎麼會做類似下面的? historyType在Adapt中不是公認的類型。
Type historyType = Type.GetType("Domain.MainBoundedContext.CALMModule.Aggregates.LocationAgg." + modifiedEntry.GetType().Name + "History");
ServiceLocationHistory history = adapter.Adapt<ServiceLocation, historyType>(modifiedEntry as ServiceLocation);
historyRepository.Add(history);
編輯: 我落得這樣做:
ServiceLocationHistory history = adapter.GetType()
.GetMethod("Adapt", new Type[] { typeof(ServiceLocation) })
.MakeGenericMethod(typeof(ServiceLocation), typeof(ServiceLocationHistory))
.Invoke(adapter, new object[] { modifiedEntry as ServiceLocation })
as ServiceLocationHistory;
注意,重複的問題,同時包含「爲什麼你不應該這樣做」,以及「如何做到這一點,如果我需要」由馬克Gravell。 –