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 / September 2007

Tip: Looking for answers? Try searching our database.

Custom CodeDomSerializer issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lionel - 24 Sep 2007 17:04 GMT
Hi All,

I wrote a custom CodeDom serializer class that first invokes default
serialization for a class, after which it does some custom code
generation.

public override object Serialize(IDesignerSerializationManager
manager, object value)
{
CodeDomSerializer baseSerializer =
(CodeDomSerializer)manager.GetSerializer(myBaseType,
typeof(CodeDomSerializer));
object codeObject = baseSerializer.Serialize(manager, value);

//custom code gen here...
}

My class uses the following attributes to specify the above
serializer:

[DesignerSerializer(typeof(MyCustomSerializer),
typeof(CodeDomSerializer))]
public partial class MyClass : UserControl
{
.....
}

The custom code looks fine, but the MyClass instance variable is being
generated local to the InitializeComponent() method:

private void InitializeComponent()
{
           MyControls.MyClass myClass1 = new MyControls.MyClass();
...
           //
           // MyClass code generator
           // Updated on Monday, September 24, 2007 at 4:40:42 PM
           //
           myClass1.ShowImage = true;
           myClass1.Location = new System.Drawing.Point(149, 3);
...
}

I want the instance to be defined as a class level variable, rather
than inside InitializeComponent(). I have read that an
InstanceDescriptor can help specify this, but am as yet unable to get
it working.

Would appreciate any insights you have on doing so.

Thanks,
Lionel
G Himangi - 25 Sep 2007 09:36 GMT
I think a local variable will be generated only if you create it through the
IDesignerHost.CreateComponent method.

---------
- G Himangi,   Sky Software       http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------

> Hi All,
>
[quoted text clipped - 48 lines]
> Thanks,
> Lionel
Lionel - 25 Sep 2007 10:24 GMT
Thanks for your reply. Where should I use
IDesignerHost.CreateComponent in the serialization process?

When commenting out the [DesignerSerializer] attribute on my class I
see that VS.NET automatically creates the myClass1 variable external
to InitializeComponent(), at class scope.

//[DesignerSerializer(typeof(MyCustomSerializer),
typeof(CodeDomSerializer))]
public partial class MyClass :UserControl
{
.....
}

But by adding the attribute the variable is once again created inside
InitializeComponent(), so I assume theres something I'm not specifying
correctly in my custom serializer code?

I would have expected Serialize(manager, value); to have a flag
indicating if I'd like it serialized locally, or at class level.

Thanks,
Lionel

> I think alocalvariable will be generated only if you create it through the
> IDesignerHost.CreateComponent method.
[quoted text clipped - 60 lines]
> > Thanks,
> > Lionel
Lionel - 25 Sep 2007 14:23 GMT
Never mind, solved it...

> Hi All,
>
[quoted text clipped - 51 lines]
> Thanks,
> Lionel
schneider - 25 Sep 2007 14:58 GMT
Would be nice to know...

> Never mind, solved it...
>
[quoted text clipped - 53 lines]
>> Thanks,
>> Lionel

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.