私はこれへの正しいアプローチを見つけるのに苦労しています:
私のデータ構造:
public abstract class Flow
{
public virtual double Value { get; set; }
public virtual DateTime Time { get; set; }
}
public class InboundFlow : Flow
{
}
public class OutboundFlow : Flow
{
}
これらのデータ構造のコレクションを含むビジネス オブジェクト
public abstract class Fluent
{
public virtual IList<Flow> FlowCollection { get; set; }
public virtual double InitialBaseflow { get; set; }
}
public class Affluent : Fluent
{
public new virtual IList<InboundFlow> FlowCollection { get; set; }
}
public class Effluent : Fluent
{
public new virtual IList<OutboundFlow> FlowCollection { get; set; }
}
私が使用しようとしている一般的な方法:
private static void FindInitialBaseflow<T>(ref T fluent) where T : Fluent
{
var linqFluent = fluent;
var flows = linqFluent.FlowCollection.ToList().FindAll(
flow =>
flow.Time >= SOME_DATE &&
flow.Time < SOME_OTHER_DATE);
var initialBaseflow = flows.Average(flow => flow.Value);
fluent.InitialBaseflow = Math.Round(initialBaseflow, 5);
}
私の問題は、linq メソッドで「linqfluent.FlowCollection」を呼び出すと、 null である基本クラス Fluent のFlowCollection が呼び出されることです。
代わりに、子のプロパティの使用を強制するにはどうすればよいですか? ありがとう!