Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   XmlSerializers, Structs, and Default Constructors (http://www.velocityreviews.com/forums/t300455-xmlserializers-structs-and-default-constructors.html)

Flinky Wisty Pomm 06-19-2006 01:23 PM

XmlSerializers, Structs, and Default Constructors
 
Hi, this is just out of curiosity really. I had a struct, requirements
changed and I needed to inherit from it, so I made it into a class.

After the change, XmlSerializer choked because XmlSerializable classes
require a default constructor. Why don't structs?


bruce barker \(sqlwork.com\) 06-19-2006 04:00 PM

Re: XmlSerializers, Structs, and Default Constructors
 
structs are not objects, but rather a value types. they are allocated on the
stack, rather than the heap. to improve value type performance, they do not
have contructors like objects.

-- bruce (sqlwork.com)

"Flinky Wisty Pomm" <Pathogenix@gmail.com> wrote in message
news:1150723382.494382.312230@r2g2000cwb.googlegro ups.com...
> Hi, this is just out of curiosity really. I had a struct, requirements
> changed and I needed to inherit from it, so I made it into a class.
>
> After the change, XmlSerializer choked because XmlSerializable classes
> require a default constructor. Why don't structs?
>




Flinky Wisty Pomm 06-20-2006 07:41 AM

Re: XmlSerializers, Structs, and Default Constructors
 
Structs DO have constructors, but I found an answer with a quick
Google. In case anyone else is sad enough to care, structs have an
explicit but hidden default constructor whose purpose is to assign
default values to field members.

That's why you can't create an explicit default constructor on a
struct, the .Net framework creates one under the covers. This default
constructor is presumably used by the XmlSerializer.

Mystery solved.


bruce barker (sqlwork.com) wrote:
> structs are not objects, but rather a value types. they are allocated on the
> stack, rather than the heap. to improve value type performance, they do not
> have contructors like objects.
>
> -- bruce (sqlwork.com)
>
> "Flinky Wisty Pomm" <Pathogenix@gmail.com> wrote in message
> news:1150723382.494382.312230@r2g2000cwb.googlegro ups.com...
> > Hi, this is just out of curiosity really. I had a struct, requirements
> > changed and I needed to inherit from it, so I made it into a class.
> >
> > After the change, XmlSerializer choked because XmlSerializable classes
> > require a default constructor. Why don't structs?
> >




All times are GMT. The time now is 04:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.