私は、次のコード(PointLine
とCalculatedLine
両方がLine
を継承)を持つ:エディタは、私はline.init()
を呼び出すときについてline
がタイプPointLine
/CalculatedLine
のものではない文句を言いVB.NETの別の変数にオブジェクトを再割り当てせずにオブジェクトをキャストするにはどうすればよいですか?
For Each line As Lines.Line In lines
''Since both Point and Calculated lines are stored in the same list in the XML files,
''we need to force them back to their original type before using them
Select Case line.GetType()
Case GetType(Lines.PointLine)
line = DirectCast(line, Lines.PointLine)
line.init()''ERROR:'init' is not a member of 'PerformanceValidation.EngineValidation.Limits.Components.Lines.Line'
myLimitSeries.Add(line.series)
Case GetType(Lines.CalculatedLine)
line = DirectCast(line, Lines.CalculatedLine)
line.init(dataTable)''ERROR:'init' is not a member of 'PerformanceValidation.EngineValidation.Limits.Components.Lines.Line'
myLimitSeries.Add(line.series)
End Select
Next
を。
元のオブジェクトは、後で使用される計算された情報を含むように「初期化」するため、PointLineまたはCalculatedLineにキャストすることが重要です。基本的には、キャストされたLineのコンテナとして機能するPointLineまたはCalculatedLine型の新しい変数を作成したくありません。
私は適切なタイプの新しいラインを作成しようとしましたが(私が上記にしたくないと言ったように)、元のラインを削除して新しいラインをリストに追加しましたが、もちろん、変更されています。
Line
をPointLine
またはCalculatedLine
として一時的に扱う方法はありますか?
ありがとうございます!
そうですね。非常に清潔で、非常にエレガント。ありがとうございました! –