I’m using extension methods based on an array and I would like to know if there is an easy way to check that array got a specify size instead of me doing a copy paste of
if array.count != 1000
throw new exception "size of the array does not match"
in about ~50 extensions
this a small sample of extensions that I use, I got WAY more
<Extension()>
Public Function IsWhite(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.White) = bitPiece.White
End Function
<Extension()>
Public Function IsBlack(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Black) = bitPiece.Black
End Function
<Extension()>
Public Function IsRook(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Rook) = bitPiece.Rook
End Function
<Extension()>
Public Function IsBishop(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Bishop) = bitPiece.Bishop
End Function
<Extension()>
Public Function IsKnight(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.knight) = bitPiece.knight
End Function
<Extension()>
Public Function IsQueen(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Queen) = bitPiece.Queen
End Function
<Extension()>
Public Function IsKing(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.King) = bitPiece.King
End Function
<Extension()>
Public Function IsPawn(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Pawn) = bitPiece.Pawn
End Function
Since your array is not really an array but represents a specific data structure (a chess board), have you considered creating a dedicated type for it?