Really, the best way would be to create your ReportBaseBBS class as a generic class that must be inherited and accepts the BOs that it will represent as generic inheritance definitions. This would allow you to talk straight to the business objects in strong-typed code without having to CType the object. Here is what the report BBS base class would look like:
Step 1 - Base Report BBS Class
This clas is the abstract class that all other report BBS classes would inherit from. You'll see that the definition requires a primary business object to be specified (you can add all of the required BOs that you want to, but this is not necessary as other BBS classes could be exposed on the actual classes [i.e. MyCustomersBBS, MyOrdersBBS, etc.]). But we know that we are going to need at least one business object for each BBS. So you can see that the class defined a generic parm called TPrimaryBO (you can call this whatever you want). This will require a BusinessLayer class with a constructor (that is what the new() is doing).
/// <summary>
/// Create the base class of the reporting engine
/// </summary>
/// <remarks></remarks>
public abstract class ReportBaseBBS<TPrimaryBO> : MicroFour.StrataFrame.Business.BusinessBindingSource where TPrimaryBO : BusinessLayer, new()
{
#region Constructors
/// <summary>
/// Default Constructor
/// </summary>
/// <remarks></remarks>
public ReportBaseBBS()
{
//-- Create a new instance of the primary business object that this class wraps
this.BusinessObject = _PrimaryBO;
}
#endregion
#region Declare Privates
private TPrimaryBO _PrimaryBO = new TPrimaryBO();
#endregion
#region Public Properties
/// <summary>
/// Exposes the primary business object so that you can reference it in code
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
public TPrimaryBO PrimaryBO
{
get
{
return _PrimaryBO;
}
}
#endregion
}
Step 2 - Creating a Customers BBS Class
The next step would be creating the custom class that inherits the ReportBaseBBS and specifies which business object to wrap. In the below example, you can see that we are inheriting the ReportBaseBBS class and supplying the business object type that will be the primary BO in this class (TPrimaryBO).
/// <summary>
/// This class is a BBS wrapper for the customers business object type
/// </summary>
/// <remarks></remarks>
public class CustomersReportBBS : ReportBaseBBS<CustomersBO>
{
}
Step 3 - Now you can directly access anything on the Primary BO
You will see in the below code sample, that once the CustomersReportBBS class is created, you can directly access the wrapped BO now through the property that was created in the ReportBaseBBS class (PrimaryBO).
public class TestCode
{
/// <summary>
/// Just shows how to use the code
/// </summary>
/// <remarks></remarks>
public TestCode()
{
CustomersReportBBS cust = new CustomersReportBBS();
//-- You can now access every method, etc. strong-typed through code since it is exposed
// through the PrimaryBO property using the typed generic.
cust.PrimaryBO.FillWithMyCoolMethod();
}
}
This would be the cleanest way to achieve what you are trying to do. For those VB.NET developers, here is the VB code:
VB.NET - Step 1
''' <summary>
''' Create the base class of the reporting engine
''' </summary>
''' <remarks></remarks>
Public MustInherit Class ReportBaseBBS(Of TPrimaryBO As {BusinessLayer, New})
Inherits MicroFour.StrataFrame.Business.BusinessBindingSource
#Region " Constructors "
''' <summary>
''' Default Constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
'-- Create a new instance of the primary business object that this class wraps
Me.BusinessObject = _PrimaryBO
End Sub
#End Region
#Region " Declare Privates "
Private _PrimaryBO As New TPrimaryBO()
#End Region
#Region " Public Properties "
''' <summary>
''' Exposes the primary business object so that you can reference it in code
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property PrimaryBO() As TPrimaryBO
Get
Return _PrimaryBO
End Get
End Property
#End Region
End Class
VB.NET - Step 2
''' <summary>
''' This class is a BBS wrapper for the customers business object type
''' </summary>
''' <remarks></remarks>
Public Class CustomersReportBBS
Inherits ReportBaseBBS(Of CustomersBO)
End Class
VB.NET - Step 3
Public Class TestCode
''' <summary>
''' Just shows how to use the code
''' </summary>
''' <remarks></remarks>
Public Sub New()
Dim cust As New CustomersReportBBS()
'-- You can now access every method, etc. strong-typed through code since it is exposed
' through the PrimaryBO property using the typed generic.
cust.PrimaryBO.FillWithMyCoolMethod()
End Sub
End Class