Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi!

 

When we have a class to serialize we must ensure these 2 fundamental issues:

1- Add the Serializable attribute.

2- Leave a Sub New() constructor

 

Now, imagine that I need to protect this simple NEW() constructor, but still enable serialization... how can I do it??

 

I tryed to:

Protected Sub New()

 

But the Serialization Formatter throws an error...

 

Thanks,

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.
Posted

So there's no way I can protect a serializable class from beeing "constructed" with a default constructor?

 

hummmmmmm sounds strange... and anoying at the same time... sucks!

 

Alex :o

Software bugs are impossible to detect by anybody except the end user.
Posted

Yeah, classes need to be instatiated, but shurelly you have already created a class that must receave at leat a parameter on the constructor!

 

If this parameter is essessial to the work of the class, and also that class must be serialisable, that means that a default (no parameters) constructors will be available to use but will generate errors if used!

 

See what I mean?

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.
Posted

Stop trying to use c++ tricks in VB :p. Besides, the best trick in c++ was to define it as private in the header, without implementing it ;)

 

I think the serialize attribute requires that the object can be instantiated from another class without any parameters. So that really conflicts with what you want to do here, either no more serializable or change the check on the parameter needed for instantiation by using something like an initialize method or so.

Nothing is as illusive as 'the last bug'.
  • *Gurus*
Posted
I don't believe I've ever created a class that needed a parameter to be passed to its constructor. If the parameter is null the code throws a descriptive exception to the caller on invocation of a method (or less likely a property accessor) that requires the parameter. This is normal.
Posted
The advantage would be that the compiler performs the check and doesnt allow the code to build, instead of a run-time error that might be found with sufficient testing, but also might not be found until found by the end-user who is very good at finding the weirdest bugs ;).
Nothing is as illusive as 'the last bug'.
Posted

Finally someone who understands me... :D

 

This may sound a little nonsence if you think about classes for our own use, but if we're talking about classes from a public control, any end user may instatiate the class the wrong way, not knowing that's wrong untill the exception arrises... Then the debugging may be somehow hard to find for somehone who doesn't know how that really works...

 

I think that at least the Protected declaration should work...

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...