all groups > visual c > march 2007 >
You're in the

visual c

group:

Syntax for Serializing generic ref class


Syntax for Serializing generic ref class Edward Diener
3/31/2007 10:20:42 AM
visual c: 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
Re: Syntax for Serializing generic ref class Chris Taylor
4/1/2007 5:32:40 PM
Hi,

Put the attribute after the generic declaration ie.

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

Hope this helps

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


[quoted text, click to view]
Re: Syntax for Serializing generic ref class Ben Voigt
4/2/2007 2:00:15 PM

[quoted text, click to view]

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

[quoted text, click to view]

AddThis Social Bookmark Button