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 / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

Syntax for Serializing generic ref class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward Diener - 31 Mar 2007 15:20 GMT
Following the example in the help for the generic List class, which
shows the Serializable attribute being used on the generic class, like so:

[SerializableAttribute]
generic<typename T>
public ref class List : IList<T>, ICollection<T>,
    IEnumerable<T>, IList, ICollection, IEnumerable

I try to do the same for my own generic class, like so:

[System::SerializableAttribute]
generic <typename T>
public ref class AClass
{
// Lots of goodies
};

only to be met with compiler error:

error C2059: syntax error : 'generic'

on line 2. If I remove the [System::SerializableAttribute] , all is
well, but naturally I want it so that my class can be serialized.

What is the magic incantation <g> to get this to work properly ? I have
tried a number of different variations without getting this to work, so
evidently my genii is on vacation.
Chris Taylor - 01 Apr 2007 15:32 GMT
Hi,

Put the attribute after the generic declaration ie.

generic<typename T>
[SerializableAttribute]
public ref class List : IList<T>, ICollection<T> ...

Hope this helps

Signature

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

> Following the example in the help for the generic List class, which shows
> the Serializable attribute being used on the generic class, like so:
[quoted text clipped - 23 lines]
> tried a number of different variations without getting this to work, so
> evidently my genii is on vacation.
Ben Voigt - 02 Apr 2007 20:00 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> Hope this helps

This is clearly a documentation bug at
http://msdn2.microsoft.com/en-us/library/skef48fy.aspx

>> Following the example in the help for the generic List class, which shows
>> the Serializable attribute being used on the generic class, like so:
[quoted text clipped - 23 lines]
>> tried a number of different variations without getting this to work, so
>> evidently my genii is on vacation.

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.