473,851 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing static generic UI method to business objects

Winforms UI assembly has static FormManager.For mCreator 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.

I tried code below but got compile errows shown in comments.
How to fix ?

Andrus.
////// This code is in Entry, Winforms UI assembly and has references to
business assembly

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

class test
{
static void Main()
{
//Invalid expression term '>'
new
Customer().DoBu sinessLogicAndS howResultFormsU singFormManager (FormManager.Fo rmCreator<>);
}
}
public static class FormManager
{
public static void FormCreator<TEn tity>()
{
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
DoBusinessLogic AndShowResultFo rmsUsingFormMan ager<TChildEnti ty>(
ActivateEntityF orm<TChildEntit yformCreator)
{
//The variable 'x' cannot be used with type arguments
formCreator<Chi ldentity1>();
formCreator<Chi ldentity2>();
}

}

class Childentity1 { }
class Childentity2 { }

Oct 26 '08 #1
2 2475
On Sun, 26 Oct 2008 14:51:23 -0700, Andrus <ko********@hot .eewrote:
Winforms UI assembly has static FormManager.For mCreator 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.

I tried code below but got compile errows shown in comments.
How to fix ?
You have to specify the type for the generic method. For example,
"FormManager.Fo rmCreator<Child entity1>".

From your example, it seems to me that the "Childentit y1" class is
probably not available in your UI assembly, which means you wouldn't be
able to do it that way. But that's the only way to get the generic method
to work. When you use a generic, the compiler has to know exactly what
type is being used for the generic, unless of course the generic is being
used in the definition of some other generic.

So you'll have to accomplish your goal without using a generic method like
that. Since your example doesn't really make it very clear why you want
to instantiate forms this way (for example, the code you posted could just
as easily have passed a string to the method, or an actual type, rather
than the method being generic...you never really use the generic-ness of
the method in any way), it's hard to suggest what alternative might be
appropriate. If you want help with that, you probably should try to be
more specific about your question.

Pete
Oct 26 '08 #2
Peter,

Thank you.
You have to specify the type for the generic method. For example,
"FormManager.Fo rmCreator<Child entity1>".

From your example, it seems to me that the "Childentit y1" class is
probably not available in your UI assembly, which means you wouldn't be
able to do it that way. But that's the only way to get the generic method
to work. When you use a generic, the compiler has to know exactly what
type is being used for the generic, unless of course the generic is being
used in the definition of some other generic.
Childentity1 and other business entities arve 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.
So you'll have to accomplish your goal without using a generic method like
that. Since your example doesn't really make it very clear why you want
to instantiate forms this way (for example, the code you posted could just
as easily have passed a string to the method, or an actual type, rather
than the method being generic...you never really use the generic-ness of
the method in any way), it's hard to suggest what alternative might be
appropriate. If you want help with that, you probably should try to be
more specific about your question.
I'm sorry I was not clear.
In real code FormCreator<TEn tity 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<TEn titymethod 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.
Maybe come MVP pattern can used.

Andrus.

Oct 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3191
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
25
5070
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
9
2672
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database operations on purchase orders and inventory. I have created a PurchaseOrder class and Inventory class to encapsulate operations like creating POs, finding items, etc. These two classes are used extensively from different parts of the app.
12
5349
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
15
2168
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data access layers, should I use static methods? Or, should I code the classes so that they have to be instantiated? I've seen examples of both, and I'm not sure which is the "preferred" or "best" way. Thanks.
5
3223
by: pali | last post by:
Hi, I was just wondering, why is not possible to make a member of a class BOTH abstract and static? MSDN says just that's in an error, not why this is so. In a nutshell, I need this: I have an abstract base class called EntityBase that all my other business objects are derived from. I want to be able to load and save them in a generic manner. I use a static method called EntityBase.GetByID(int id) and a member method called...
4
3151
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my question In short my question is why when I pass a generic type directly to the formatObject function it works fine, but when I pass it to the checkText function where it is itself a generic argument, and then it is passed to formatObject, it is seen...
17
7266
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
10
1945
by: Egghead | last post by:
Hi all, Can someone kindly enough point me to some situations that we shall or "must" use Generic Class? I can foresee the Generic Method is powerful, but I can not find a single situation that I will need the Generic Class, given there are so many other options. -- cheers,
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9744
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10725
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7900
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.