Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing generic delegate to business objects
Message
From
31/10/2008 00:32:18
 
 
To
28/10/2008 14:46:10
General information
Forum:
ASP.NET
Category:
Class design
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01357813
Message ID:
01358559
Views:
18
Andrus,

I don't know if this will work, because like Tim, I'm not 100% sure I understand what you're trying to do. But, as far as passing a delegate to a method, you're only missing the correct anonymous delegate syntax. Try this:
new Customer().DoBusinessLogicAndShowResultFormsUsingFormManager(delegate(){FormManager.FormCreator<>});
I'm not sure if you need the type as well, so you might need to do it like this;
new Customer().DoBusinessLogicAndShowResultFormsUsingFormManager(delegate(){FormManager.FormCreator<TEntity>});
~~Bonnie





>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 { } 
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform