我可以避免为从接口派生的类编写样板代码吗?

时间:2018-05-08 17:48:03

标签: inheritance interface f# boilerplate

我有很多实现接口的类。每当我定义一个类时,我必须在类定义中编写类似的东西:

interface Model.IModel with

        member this.Assets          = modelArg.Assets
        member this.AuxData         = modelArg.AuxData
        member this.Benchmark       = modelArg.Benchmark
        member this.CalcPeriods     = modelArg.CalcPeriods
        member this.CashTicker      = modelArg.CashTicker
        member this.Description     = modelArg.Description
        member this.FirstValidDate  = modelArg.FirstValidDate
        member this.Name            = modelArg.Name
        member this.ParamData       = modelArg.ParamData
        member this.ParamList       = modelArg.ParamList
        member this.Strategy        = modelArg.Strategy

        member this.CalcStartTime with get() = calcStartTime and
                                       set v = calcStartTime <- v

        member this.Counter with get() = counter and
                                 set v = counter <- v

有没有办法避免为从IModel接口派生的每个类重复这个?代码在所有情况下都是相同的。

0 个答案:

没有答案