Skip to content

Commit

Permalink
Added Constraints.Constraint that accepts a predicate as the constrai…
Browse files Browse the repository at this point in the history
…nt. Closes #14.
  • Loading branch information
hisystems committed Mar 10, 2012
1 parent 34ec24a commit cf7d095
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Contraints/Constraint.vb
@@ -0,0 +1,39 @@

' ___________________________________________________
'
' (c) Hi-Integrity Systems 2012. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On

Namespace Constraints

''' <summary>
''' </summary>
Public Class Constraint(Of T)
Implements IConstraint(Of T)

Private pobjPredicate As Func(Of T, Boolean)

Public Sub New(ByVal objPredicate As Func(Of T, Boolean))

If objPredicate Is Nothing Then
Throw New ArgumentNullException
End If

pobjPredicate = objPredicate

End Sub

Private Function ValueSatisfiesConstraint(value As T) As Boolean Implements IConstraint(Of T).ValueSatisfiesConstraint

Return pobjPredicate.Invoke(value)

End Function

End Class

End Namespace
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -114,6 +114,7 @@
<Compile Include="Attributes\SubsetAttribute.vb" />
<Compile Include="Attributes\TableAttribute.vb" />
<Compile Include="Attributes\TableJoinAttribute.vb" />
<Compile Include="Contraints\Constraint.vb" />
<Compile Include="Contraints\RegExConstraint.vb" />
<Compile Include="Contraints\DateIsTodayOrFutureForNewObjectConstraint.vb" />
<Compile Include="Contraints\NumberIsMaximumOrLesserConstraint.vb" />
Expand Down

0 comments on commit cf7d095

Please sign in to comment.