Hi,
I am trying to implement a multi-purpose user control with generics. I can develop the generic class, and can instantiate concrete child classes inherited from the genric class, but have problems passing the instantiated concrete classes to methods. -
/// <summary>
-
/// Represents an adapter that can take different types of dataset objects and perform some basic functions.
-
/// </summary>
-
/// <typeparam name="TDataset">Any type of dataset.</typeparam>
-
/// <typeparam name="TTableAdapter">Any type of table adapter.</typeparam>
-
/// <typeparam name="TDataTable">Any type of datatable.</typeparam>
-
public class GridEntity<TDataset, TTableAdapter, TDataTable>
-
where TDataset : DataSet, new()
-
where TTableAdapter : System.ComponentModel.Component, new()
-
where TDataTable : System.Data.DataTable, new()
-
{
-
protected TDataset dataset;
-
protected TTableAdapter mainTableAdapter;
-
protected TDataTable mainDataTable;
-
protected System.ComponentModel.IContainer components = null;
-
protected BindingSource mainBindingSource;
-
-
/// <summary>
-
/// Returns the Binding Source Data Member.
-
/// </summary>
-
public virtual string BindingSourceDataMember
-
{
-
get{}
-
}
-
-
/// <summary>
-
/// Constructor
-
/// </summary>
-
public GridEntity(string datasetName)
-
{
-
dataset = new TDataset();
-
dataset.DataSetName = datasetName;
-
dataset.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
-
components = new System.ComponentModel.Container();
-
mainBindingSource = new System.Windows.Forms.BindingSource(this.components);
-
mainBindingSource.DataSource = dataset;
-
mainBindingSource.DataMember = BindingSourceDataMember;
-
mainTableAdapter = new TTableAdapter();
-
mainDataTable = new TDataTable();
-
}
-
-
-
/// <summary>
-
/// Returns the Main Dataset
-
/// </summary>
-
public TDataset MainDataSet
-
{
-
get
-
{
-
return dataset;
-
}
-
}
-
-
/// <summary>
-
/// Returns the Main Table Adapter.
-
/// </summary>
-
protected internal TTableAdapter MainTableAdapter
-
{
-
get
-
{
-
return mainTableAdapter;
-
}
-
}
-
-
/// <summary>
-
/// Returns the Main Data table.
-
/// </summary>
-
protected internal TDataTable MainDataTable
-
{
-
get
-
{
-
return mainDataTable;
-
}
-
}
-
-
/// <summary>
-
/// Returns the Main Binding Source.
-
/// </summary>
-
public BindingSource MainBindingSource
-
{
-
get
-
{
-
return mainBindingSource;
-
}
-
}
-
-
}
-
-
public static GridEntity<TDataset, TTableAdapter, TDataTable> Instance()
-
{
-
return new GridEntity<TDataset, TTableAdapter, TDataTable>("MyDataset");
-
}
-
}
-
-
Then I have a class inherited from GridEntity: -
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Data;
-
-
public class ChildGridEntity : GridEntity<MyNamespace.Data.MyDataset, MyNamespace.MyData.MyDatasetTableAdapters.ChildAdapter TableAdapter, MyNameSpace.Data.MyDataset.ChildDataTable>
-
{
-
-
some specific implementation...
-
}
-
}
-
Then I am trying to instantiate a generic class and pass it as a parameter: - public enum Entity
-
{Child,
-
Child2,
-
...
-
}
-
-
public class GridEntityAbstractFactory()
Here is where I am having problems:
public static GridEntity(Enti ty entity) - {
-
switch (entity)
-
{
-
Case Entity.Child1:
-
ChildGridEntity gridEntity=new ChildGridEntity()
-
break;
-
...
-
}
-
}
-
And finally I can't seem to do this from the client: - public class Client
-
{
-
-
public Client(
-
{
-
IntializeComponents(gridEntity);
-
}
-
The purposes is for me to have my factory create child objects which can then be passed as needed like in the method InitializeCompo nents to do the same tasks irrespective of which specific child object they are. I know this can be done with reflection, but I am trying to avoid doing that. If you see a way of making this work, or another way of doing this, it would be greatly appreciated.
Thanks.
4 3309 tlhintoq 3,525
Recognized Expert Specialist TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Hi,
I am not sure I understand your answer. I used the code tags and the code seems to be embedded correctly. When I looked at my original post, I didn't see anything wrong with the formatting. Could you clarify what doesn't look right and what you mean by wrapping the code tags with # , as I thought I just needed to put the code tags around my code and that would take care of it.
Thanks!
tlhintoq 3,525
Recognized Expert Specialist
Your code tags were <code>
instead of [code]
The reason it looks right is that I went in and edited the tags (if you look at the bottom of the post it will say
Last edited by tlhintoq; 1 Hour Ago at 09:54 AM. Reason: [code] ...Your code goes between code tags [code]
I was just pointing out instead of typing [code] you can just select a block then hit the '#' button in the format bar. As well as giving you a link to all the other formatting tags that aren't so well known like HIGHLIGHT or how to insert an image without it being a thumbnail.
[IMGNOTHUMB]http://files.me.com/tlhintoq/j61pjn[/IMGNOTHUMB]
instead of
[IMG]http://files.me.com/tlhintoq/j61pjn[/IMG]
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Murat Tasan |
last post by:
so here is another general question about java...
why can't you declare an abstract static method.
i can envision the case (indeed i have experienced the case) where one
would want an abstracct superclass, with an abstract method such that all
subclasses that implement this method make that method static.
basically, the abstract class declares an abstract method that should be
static for all implementations (for example a factory...
|
by: Medi Montaseri |
last post by:
Hi,
Given a collection of similar but not exact entities (or products)
Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern
to provide a common interface to these products. So I shall have an
Abstract Base called 'Car' implemented by Toyota, Ford, and Buick.
Further I'd like to enable to client to say
Car *factory;
|
by: f00sion |
last post by:
I found a good tutorial of how to supply the objects without having
the implementation files on the client. This was working great until I
realized that I couldnt use any constructors with server activated
objects, so I switched to client activated objects only to run into
the next roadblock, doh! can't instantiate abstract classes... here is
a simple example of the structure, im sure there is a way to do it to
allow instantiation but I am...
|
by: Martyn Lawson |
last post by:
Hi,
I am currently working as an Analyst on a .NET Web Project using ASP.NET and
C#.NET.
I have a couple of, at least what should be, quick questions:
1. My understanding of UML says that the Controller classe of a Sequence
Diagram should be implemented as a private class within a component.
However, my Programmer has said that since the ASP code lives outside the
|
by: Chris Capel |
last post by:
What is the rationale behind the decision not to allow abstract static class
members? It doesn't seem like it's a logically contradictory concept, or
that the implementation would be difficult or near-impossible. It seems like
it would be useful. In fact, there's a place in my code that I could make
good use of it. So why not?
Chris
| |
by: Tamir Khason |
last post by:
I have some classes that basicly do the same things but different way.
There are no default constructors in those classes each constructor should
recieve same value
So
Fooclass:MyBasicClass or Fooclass:IBasicClass
and I want to be able to call form program something like this:
|
by: Michael McCarthy |
last post by:
I want to develop plugin support for a system.montitor module I am
working on. A lot of the modules will do mostly interop stuff for an
older system, but I want to use it myself as well to monitor event logs
and other things as I think of them...
I've seen two ways of doing this, the abstract class factory, or the
interface... the module logic is fairly simple, watch something -> get
the result -> notify / fix / and or log it...
I've...
|
by: Anders Borum |
last post by:
Hello!
Whilst refactoring an application, I was looking at optimizing a
ModelFactory with generics. Unfortunately, the business objects created by
the ModelFactory doesn't provide public constructors (because we do not
allow developers to instantiate them directly).
Because our business objects are instantiated very frequently, the idea of
using reflection sounds like a performance killer (I haven't done any tests
on this, but the...
|
by: mailforpr |
last post by:
Hi.
Let me introduce an iterator to you, the so-called "Abstract Iterator"
I developed the other day.
I actually have no idea if there's another "Abstract Iterator" out
there, as I have never looked for one on the net (I did browse the
boost library though). It doesn't matter right now, anyway.
To put it simply, Abstract Iterator is mainly a wrapper class. It helps
|
by: Sean Chambers |
last post by:
This is a fairly simple architecture question, just can't seem to wrap
my head around the answer.
I am using NHibernate 1.2 from the trunk to leverage generics support.
I have a User Table that has 4 different types of users:
Patron
Promoter
Admin
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |