Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
PrimaryBizObject
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01327814
Message ID:
01328065
Views:
9
Maurizio,

>On a few part of the code I have this call that retrieves all entityes of an BO
>
> this.[BO name].GetAllEntities();
>
>I would like to use some "generic" way so that I can copy/paste this piece of code to new forms, without modifying the BO name.
>
>So is there a way to do something like this:
>
> this.PrimaryBizObj.GetAllEntities();
>
>This above line does not work because this.PrimaryBizObj is of type mmBaseBusinessObject and GetAllEntities() is a method of the specific BO entity type.

Based on the way inheritance works with Generics in .NET, you can’t access the GetAllEntities() method with a reference to a generic type. You can only access this method on a specific instance of the class. That said, you *can* call GetAllData() instead, which is a method that belongs to mmBusinessObject by doing the following:
((mmBusinessObject)this.PrimaryBizObj).GetAllData();
Note that you should call this method after the call to InitializeComponent() in the form’s constructor. To harden your code even further, you can check if this.PrimaryBizObj != null and perform the cast to mmBusinessObject using the “as” operator.

Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Reply
Map
View

Click here to load this message in the networking platform