Is it Crucial for Criteria class to have an empty Public Contructor?

Is it Crucial for Criteria class to have an empty Public Contructor?

Old forum URL: forums.lhotka.net/forums/t/10366.aspx


Jav posted on Thursday, May 12, 2011

Like everyone else much of my SL coding involves data access using zero to one parameters.  Yesterday I needed to create a Criteria class for three parameters, What I thought was a no-sweat operation turned into a nightmare when, no matter what I did, my DataPortal_Fetch(MyCriteria crit) would never get hit.

Originally I had subclassed BusinessBase.  After reading the CSAL4 book, I subclassed CriteriaBase, but still no luck.  Then I remembered using a Criteria class for something many months ago, and that one had been working ever since.  I though I'll take a look.  The only difference I found was a Public Criteria() { } sitting the in the class.

Not expecting anything particular, I added the same into my new Criteria class - and boom thare it was.  My lonely little DataPortal_Fetch(MyCriteria crit) had a hit.  Yea!!  Was it just a fluke, or was this what was sorely needed all along?  That's the question.

 

 

RockfordLhotka replied on Thursday, May 12, 2011

The MobileFormatter requires that all serializable types have a public default constructor.

Because I've been doing so much SL/WP7, I have taken to always implementing public default constructors (actually I almost never implement any constructors, so the compiler creates the public default ctor).

Jav replied on Saturday, May 14, 2011

RockfordLhotka
so the compiler creates the public default ctor

For some reason, the compiler was not creating the default constructor in my Criteria class - or so it seems.  I used to always add a default public constructor.  Then about a month ago I started using CodeRush - a pesky little add-on which has been driving me nuts.  One of its pet goals in life is to make me remove all Default Public constructors. (The other is to keep telling me that I do not need to import Csla.Serialization)

Javed

Copyright (c) Marimer LLC