AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

CSLA: Enhance Criteria.Generated Class ToString to include partial method hook. #298

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. If you want to extend the criteria for a business object for more fields
or wildcard searching the current error message uses the Criteria.Tostring
method to report zero records returned, where your extended properties are
not included in that message.
2. Need to extend OverrideToString to include a partial method hook.
3. See attached template change as an example.

What is the expected output? What do you see instead?
    Public Overrides Function ToString() As String
        Dim cancel As Boolean = False
        Dim result As String = String.Empty
        OnOverridingToString(cancel, result)

        If Not cancel Then
            If _bag.Count = 0 Then
                Return "No criterion was specified"
            End If

            For Each key As KeyValuePair(Of String, Object) In _bag
                result += String.Format("[{0}] = '{1}' AND ", key.Key,
key.Value)
            Next

            Return result.Remove(result.Length - 5, 5)
        Else
            Return result
        End If
    End Function

    #End Region

    #Region "Criteria partial methods"

    Partial Private Sub OnOverridingToString(ByRef cancel As Boolean, ByRef
result As String)
    End Sub

    #End Region

What version of the product are you using?
r1475

Please provide any additional information below.
Template location ..\Templates\Frameworks\Csla\VisualBasic\BusinessLayer
\Internal

Here is an example of the partial class in action.
    Const cWILD As String = "%"
    Private _FullNameWild As String = cWILD
    Private _StateWildWild As String = cWILD

    ''' <summary>
    ''' Extended sp_Consultant_Select sp to do this.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property FullNameWild() As System.String
        Get
            Return _FullNameWild
        End Get
        Set(ByVal value As System.String)
            _FullNameWild = SqlSyntaxHelper.WhereTextCleanup(value, False,
True, True)
        End Set
    End Property

    Public Property StateWild() As System.String
        Get
            Return _StateWildWild
        End Get
        Set(ByVal value As System.String)
            _StateWildWild = SqlSyntaxHelper.WhereTextCleanup(value, False,
True, True)
        End Set
    End Property

    ''' <summary>
    ''' Adds the extra wildcard details to the search results.
    ''' </summary>
    ''' <param name="cancel"></param>
    ''' <param name="result"></param>
    ''' <remarks>Log this change with codesmith templates.</remarks>
    Private Sub OnOverridingToString(ByRef cancel As Boolean, ByRef result
As String)\
        cancel = True
        If _bag.Count > 0 Then

            For Each key As KeyValuePair(Of String, Object) In _bag
                result += String.Format("[{0}] = '{1}' AND ", key.Key,
key.Value)
            Next
            result.Remove(result.Length - 5, 5)
        End If

        '   Extra wild card search items.
        result += String.Format("[{0}] like '{1}' AND ", "chrBDMName",
_FullNameWild)
        result += String.Format("[{0}] like '{1}'", "chrBDMFKState",
_StateWildWild)

    End Sub

Original issue reported on code.google.com by JenasysD...@gmail.com on 4 Mar 2010 at 6:16

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 4 Mar 2010 at 11:43

GoogleCodeExporter commented 9 years ago
Hello,

This has been fixed in revision 1558.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 26 Mar 2010 at 3:19

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 21 Jun 2010 at 8:08