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 / Visual Studio.NET / IDE / October 2007

Tip: Looking for answers? Try searching our database.

design time, abstract, TypeDescriptionProvider

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kenneth@nospam.nospam - 11 Oct 2007 17:29 GMT
I was attempting to get around the VS2005 designer giving error messages
because a usercontrol is inherited from an abstract class.

Made use of   TypeDescriptionProvider   to try this  (found in a online
article).  And it does work, until the project gets recompiled after the
control has been open in the designer.  (can compile before opening control
without issue (appearently))

Using two instances of VS to debug the design time, what I saw following a
recompile, the Type objectType passed into GetReflectionType() (see code
below)  says its the correct type, has the right name, the right assembly,
etc, but the passed objectType (X) does not compare as being equal to a  
typeof(X).  

The design window can be closed, the solution can be closed, the problem
continues.   VS has to be shutdown and relaunched before this stops occuring.
(i.e. the passed objectType (X) does compare as equal to typeof(X) )

I have VS sp1 installed.  Tried installing hotfix  KB912019.  No effect.

TIA for your assistance

***************************************************
***************************************************

   [TypeDescriptionProvider(typeof(ConcreteClassProvider_CCBB))]
   abstract public class X: System.Windows.Forms.UserControl
   { ... }

   // Here is a concrete version of X that acts as a stand in
   internal class ConcreteForm_CCBB : X
   {
   }

   // Here is our type description provider.  All our provider needs to
   // do is return ConcreteForm as the reflection type.
   internal class ConcreteClassProvider_CCBB : TypeDescriptionProvider
   {

     // Because we only want to augment the metadata for AbstractForm,
instead of
       // completely replace it, we pass into the base class the current type
       // description provider.  This is the provider that normally handles
       // metadata for AbstractForm.  By doing this all we have to do is
       // override the areas we want to change.
       public ConcreteClassProvider_CCBB()
           : base(TypeDescriptor.GetProvider(typeof(X)))
       {
           System.Console.WriteLine("in ConcreteClassProvider_CCBB");
       }

       // Tell anyone who reflects on us that the concrete form is the
       // form to reflect against, not the abstract form. This way, the
       // designer does not see an abstract class.
       public override Type GetReflectionType(Type objectType, object
instance)
       {
           System.Console.WriteLine("in
ConcreteClassProvider_CCBB.GetReflectionType");

           if (typeof(X).Equals(typeof(X)))
           {
               //   TRUE
               System.Console.WriteLine("X matches  X");
           }
           if (objectType.Equals(objectType))
           {
               //    TRUE
               System.Console.WriteLine("objectType matches objectType");
           }
           if (objectType.Equals(typeof(X)))
           {
           //    FALSE
               System.Console.WriteLine("it matches X");
           }
           if (objectType.Name.Equals("X"))
           {
               //    TRUE
               System.Console.WriteLine("its Name matches X");
           }
           if (objectType.IsAbstract &&
typeof(X).IsAssignableFrom(objectType))
           {
               //    FALSE
               objectType = typeof(ConcreteForm_CCBB);
           }
           return base.GetReflectionType(objectType, instance);
       }

       // If the designer tries to create an instance of AbstractForm, we
override
       // it here to create a concerete form instead.
       public override object CreateInstance(IServiceProvider provider,
Type objectType, Type[] argTypes, object[] args)
       {
          System.Console.WriteLine("in
ConcreteClassProvider_CCBB.CreateInstance");
           if (objectType.IsAbstract &&
typeof(X).IsAssignableFrom(objectType))
           {
               objectType = typeof(ConcreteForm_CCBB);
           }

           return base.CreateInstance(provider, objectType, argTypes, args);
       }
   }
kennethm@nospam.nospam - 17 Oct 2007 16:49 GMT
... updated alias, it wasnt working...  
still wonder if vs ide is holding onto some old reference to an object that
has changed,  which then causes this behavior???

Rate this thread:







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.