Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / August 2006

Tip: Looking for answers? Try searching our database.

Generic controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GROM - 20 Jul 2006 18:50 GMT
Hi group

I have created a generic control such as this one :
public class SuperControl<E> : Control{}

It work very fine, but i can't have it in design time.

I saw on this group that it is a known problem, and that the designer
don't know how to work with generics. My first question is Have you
found  a solution, or a work around, since the last post about this
problem ?

I have start with a new class :
public class SuperControl2 : SuperControl<object>
{
  public SuperControl2()
  {
  }
}
(full implementation).
and i can have it in my design time, it works fine, but it is not very
usefull a runtime.

i create a designer class to help SuperControl2  to generate some good
code (with real class instead of object). My goal is to make all the
design using the SuperControl2, witch exactly look like another
SuperControl<>, but the compilation give the good
SuperControl<SuperClass>. I think about the code generated about this
SuperControl2 contains code like this one :

#if DESIGN
   MyControl = new SuperControl2();
#else
   MyControl = new SuperControl2<SuperClass>();
#endif

I don't know how to influence the code generation, i have to learn more
about that now. I have currently no idea about all that.

Please tell me if i am crazy or idiot :)  or if i have miss something.
Really please
Is it a good way to start ?
Is it a good solution  ?
is it a big job ?

have you any idea about this problem/solution ?
please give me some link about that.

thank you!

ROM
Dave Sexton - 13 Aug 2006 21:10 GMT
Hi ROM,

I recommend choosing a better architecture to begin with, specifically one that is polymorphic.

Determine the functionality that you need from the Typed parameter implementation and create either an interface or abstract class
to encapsulate that functionality, such as ISuperControlTask.  Declare a protected factory method for its creation within
SuperControl.  This architecture is used by the framework in many cases and will probably suit your needs well, but you have many
choices in this matter and you should analyze your situation carefully and choose the best one.

Here's a quick example that makes use of an abstract class, lazy initialization, a factor method and a private, default
implementation.
If you need to extend the SuperControl or a SuperControlTask to add more functionality you can simply create two more classes that
inherit from each.

HTH

public abstract class SuperControlTask
{
   public abstract void PerformTask();
}

public class SuperControl : Control
{
   protected SuperControlTask Task
   {
       get
       {
           EnsureTask();

           return task;
       }
   }

   private SuperControlTask task;

   public void PerformTask()
   {
       EnsureTask();

       task.PerformTask();
   }

   private void EnsureTask()
   {
       if (task == null)
       {
           // lazy task initialization

           task = CreateTask();

           if (task == null)
               throw new InvalidOperationException("The SuperControl is not associated with a SuperControlTask.");
       }
   }

   protected virtual SuperControlTask CreateTask()
   {
       return new DefaultSuperControlTask();
   }

   private class DefaultSuperControlTask : SuperControlTask
   {
       public override void PerformTask()
       {
           // TODO: default task
       }
   }
}

Signature

Dave Sexton

> Hi group
>
[quoted text clipped - 47 lines]
>
> ROM

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.