O.K... just starting to understand Generics
Here is what I want to do...
I have two methods in a NON-GENERIC class that have the following def.
Public
Class MyClassObj private mActiveItem as ??? = Nothing private mActiveReadOnlyItem as ??? = nothing Public Sub MyFunction(Of T As CSLA.BusinessBase(Of T))(ByVal activeObj As T)mActiveItem = activeObj
End Sub Public Sub MyFunction(Of C As CSLA.ReadOnlyBase(Of C))(ByVal activeObj As C)mActiveReadOnlyItem = activeObj
End SubEnd
Class
How do i finish the Module Level definitions (the variables with the ???)? I want to set the "activeObj" coming in to a module level variable for use later.
I can not seem to figure it out... it appears I want to create a variable of type CSLA.BusinessBase(of CSLA.BusinessBase)... but that does not work. I am i going about this the wrong way?
any help would be great
ward0093
You would either store the variable as an interface (like IEditableBusinessObject) or Core.BusinessBase would probably work too (but really wouldn't be the proper approach).
To use an example I like to use - I may have a generic class called Profile<T>, of which I have Individual : Profile<Individual> and Organization : Profile<Organization>. I can't store something as simply a profile - it's a generic class template. So I put an interface on Profile<T> and expose members of Profile<T> in this interface - let's call it IProfile.
Now, I can store an IProfile - which Individual and Organization implement by nature of descending from Profile. And I can call any members declared on IProfile, such as Id, Name, Status, etc.
but than can you CType the variable back into the Class Object it originally was? I mean say i pass in a "Customer" object (def: Public Class Customer - Inherits CSLA.BusinessBase(of Customer)) and this object is stored in the module variable mActiveItem (def: private mActiveItem as IMyLocalBusinessBase)...
How do I CType(mActiveObject, CLSA.BusinessBase(Of ???))?
ward0093
If something isn't on the interface that I'm storing the variable for - let's say I have an individual stored in my IProfile variable and I want to use some functionality for individuals...
I can test the variable like this: if (myIProfile is Individual) (C#)
And then just:
Individual myIndividual = (Individual)myIProfile;
myIndividual.Gender = Gender.Male;
I'm sure there's the VB equivalent. Is this what you were asking?
maybe...
I want to CType the interface back into the complete original object
if typeof MyClassObj.activeItem is Library.Customer then
'Do Something
ElseIf typeof MyClassObj.activeReadOnlyItem is Library.CustomerInfo then
'Do Something
end
if typeof MyClassObj.activeItem is Library.Customer then
Dim customer as Library.Customer = DirectCast(MyClassObj.ActiveItem, Library.Customer)
'Do Something to customer
ElseIf typeof MyClassObj.activeReadOnlyItem is Library.CustomerInfo then
Dim customer as Library.CustomerInfo = DirectCast(MyClassObj.ActiveItem, Library.CustomerInfo)
'Do Something to customer
end
Copyright (c) Marimer LLC