在F#中实现PSHostRawUserInterface

时间:2014-10-24 01:55:35

标签: f#

我正在尝试使用F#实现示例here,并且无法弄清楚如何在PSHostRawUserInterface中正确覆盖两个重载“SetBufferContents”:

#r "System.Management.Automation"

open System
open System.Management.Automation.Host

type MyRawUserInterface() =
    inherit PSHostRawUserInterface()
    override this.BackgroundColor with get() = Console.BackgroundColor and set v = Console.BackgroundColor <- v
    override this.BufferSize with get() = Size(Console.BufferWidth, Console.BufferHeight) and set v = Console.SetBufferSize(v.Width, v.Height)
    override this.CursorPosition with get() = raise (NotImplementedException()) and set _ = raise (NotImplementedException())
    override this.CursorSize with get() = Console.CursorSize and set v = Console.CursorSize <- v
    override this.ForegroundColor with get() = Console.ForegroundColor and set v = Console.ForegroundColor <- v
    override this.KeyAvailable with get() = Console.KeyAvailable
    override this.MaxPhysicalWindowSize with get() = Size(Console.LargestWindowWidth, Console.LargestWindowHeight)
    override this.MaxWindowSize with get() = Size(Console.LargestWindowWidth, Console.LargestWindowHeight)
    override this.WindowPosition with get() = Coordinates(Console.WindowLeft, Console.WindowTop) and set v = Console.SetWindowPosition(v.X, v.Y) 
    override this.WindowSize with get() = Size(Console.WindowWidth, Console.WindowHeight) and set v = Console.SetWindowSize(v.Width, v.Height)
    override this.WindowTitle with get() = Console.Title and set v = Console.Title <- v
    override this.FlushInputBuffer() = ()
    override this.GetBufferContents(_) = raise (NotImplementedException())
    override this.ReadKey(_) = raise (NotImplementedException())
    override this.ScrollBufferContents(_, _, _, _) = raise (NotImplementedException())
    override this.SetBufferContents(origin:Coordinates, contents:BufferCell[,]) = raise (NotImplementedException())
    override this.SetBufferContents(rectangle:Rectangle, fill:BufferCell) = raise (NotImplementedException())

1 个答案:

答案 0 :(得分:1)

您需要为函数指定返回类型,因为raise没有正确的返回类型(它会引发异常)。

这应该是什么样子

override this.SetBufferContents(origin:Coordinates, contents:BufferCell[,]) : unit = raise (NotImplementedException())