vb.netcsla

Different return and declared function type result, With Strict Mode Off


i have a project which runs with strict mode off and this code.

Public Overloads Function Save() As Child
     Return MyBase.Save()
End Function

Upon turning strict mode on, an error displays:

Option Strict On disallows implicit conversions from 'Parent' to 'Child'.

My question is the parent's save that is being executed OR the child's as the parent's object is being cast to the child's type?

Long Version with all the details:

I am trying to understand what this code exactly does to reproduce it clearly in the VB, so it can be clearly ported to C#.

The project is using CSLA, there is a base object, which is inherited from the Parent of the child. Child inherits Parents which inherits Base.

There is Insert at both the child & the parent. Are both of those called, by that weird difference of the return object and the function's type?


Solution

  • If you are trying to have Parent subclass Csla.BusinessBase, and then have Child subclass Parent, you need to implement Parent like this:

    Public Class Parent(Of T)
        Inherits BusinessBase(Of Parent(Of T))
    
    End Class
    
    Public Class Child
        Inherits Parent(Of Child)
    
        Protected Overrides Function SaveAsync(forceUpdate As Boolean, userState As Object, isSync As Boolean) As Task(Of Parent(Of Child))
            Return MyBase.SaveAsync(forceUpdate, userState, isSync)
        End Function
    End Class
    

    This allows the generic type T to flow from up through the inheritance hierarchy such that the implementation of SaveAsync (or Save in older versions of CSLA) is of type Child.