Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generics, business objects, business rules [solution]
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01314400
Message ID:
01315495
Vues:
24
Patrick,

>[solution]
>After looking at patterns in mmBusinessObjectGeneric I realized that the variable, the generic to follow was , duh.
>
>
>public class ABusinessRule : mmBusinessRule
>{ ...
>   #region validate specific data type methods
>
>   public string ValidateDuplicateOrder<EntityType>(
>      ABusiness<EntityType> oBusiness,
>      string order,
>      string sku)
>         where EntityType : mmBusinessEntity, new()
>         // the right type
>         // but, what does "new()" do, or mean?
>   {
>      int recsFound = oBusiness.GetDuplicateOrder(order, sku);
>
>      if (recsFound > 0)
>         AddErrorProviderWarning(...)
>   }
>
>So, in a Order Type Business Rule:
>
>public partial class OrderType1Rules : ABusinessRule
>{ ...
>   public string ValidateDuplicateOrderType1(
>      string order,
>      string sku)
>   {
>      // note the casting of the business rule's HostObject to a compatible type
>      return ValidateDuplicateOrder((OrderType1)this.HostObject, order, sku);
>   }
>
>
>If there's a better pattern, please let me know.

You've got it! The "new()" constraint says the method is allowed to create instances of the specified entity type.

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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform