Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing generic delegate to business objects
Message
From
28/10/2008 14:46:10
 
 
To
All
General information
Forum:
ASP.NET
Category:
Class design
Title:
Passing generic delegate to business objects
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01357813
Message ID:
01357813
Views:
69
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
Next
Reply
Map
View

Click here to load this message in the networking platform