src/SqlOrderHint.psm1
|
using namespace System.Collections.Generic using module ./SortOrder.psm1 <# .SYNOPSIS Defines the sort order for a database column. #> class SqlOrderHint { <# .SYNOPSIS The name of the column for which the hint is being provided. #> [ValidateNotNullOrWhiteSpace()] [string] $Column <# .SYNOPSIS The sort order of the column. #> [SortOrder] $SortOrder <# .SYNOPSIS Creates a new order hint. .PARAMETER Column The name of the column for which the hint is being provided. #> SqlOrderHint([string] $Column) { $this.Column = $Column $this.SortOrder = [SortOrder]::Ascending } <# .SYNOPSIS Creates a new order hint. .PARAMETER Column The name of the column for which the hint is being provided. .PARAMETER SortOrder The sort order of the column. #> SqlOrderHint([string] $Column, [SortOrder] $SortOrder) { $this.Column = $Column $this.SortOrder = $SortOrder } <# .SYNOPSIS Creates a new order hint from the specified tuple. .PARAMETER Parameter The tuple providing the column name and its sort order. .OUTPUTS The order hint corresponding to the specified tuple. #> static [SqlOrderHint] op_Implicit([object[]] $OrderHint) { return [SqlOrderHint]::new($OrderHint[0] ?? "Id", $OrderHint[1] ?? [SortOrder]::Ascending) } <# .SYNOPSIS Creates a new order hint from the specified key/value pair. .PARAMETER OrderHint The key/value pair providing the column name and its sort order. .OUTPUTS The order hint corresponding to the specified key/value pair. #> static [SqlOrderHint] op_Implicit([KeyValuePair[string, SortOrder]] $OrderHint) { return [SqlOrderHint]::new($OrderHint.Key, $OrderHint.Value) } } |