Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing generic delegate to business objects
Message
De
28/10/2008 14:46:10
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Titre:
Passing generic delegate to business objects
Versions des environnements
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01357813
Message ID:
01357813
Vues:
67
Winforms UI assembly has static FormManager.FormCreator method which creates
forms taking entity as parameter.
I need to pass this method to business objects in business assembly so that
business methods can also create
forms but does not have reference to UI assembly.

Childentity1 and other business entities are avaliable to UI assembly.
I want from UI assembly to pass form manager method so that business objects
can call it by passing different business entities to this method.

In real code FormCreator uses TEntity much more. It creates list
of TEntity objects
and retrieves data for editing which may be changed by business object
worker method. Business object also passes query parameters to
FormCreator method which are not shown in this example.
I can probably pass entity name instead of type and use reflection but I'm
interested how to do this without reflection.

I tried code below but got compile errows shown in comments.


How to fix ?
////// This code is in Entry, Winforms UI assembly and has references to 
business assembly

using System.Windows.Forms;
public delegate void ActivateEntityForm<TEntity>();

class test
{
    static void Main()
    {
        //Invalid expression term '>'
        new 
Customer().DoBusinessLogicAndShowResultFormsUsingFormManager(FormManager.FormCreator<>);
    }
}


public static class FormManager
{
    public static void FormCreator<TEntity>()
    {
        Form f = new Form();
        f.Text = typeof(TEntity).Name;
        f.Show();
    }
}

/// Code below resides in business assembly and should not have references 
to assembly above

class Customer
{
    public void 
DoBusinessLogicAndShowResultFormsUsingFormManager<TChildEntity>(
        ActivateEntityForm<TChildEntity> formCreator)
    {
        //The variable 'x' cannot be used with type arguments
        formCreator<Childentity1>();
        formCreator<Childentity2>();
    }

}

class Childentity1 { }
class Childentity2 { } 
Andrus
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform