Click here to Skip to main content
15,913,854 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exception form HRESULT 0*800AC472 Pin
Bernhard Hiller3-Apr-11 22:22
Bernhard Hiller3-Apr-11 22:22 
AnswerCross-post Pin
Wendelius1-Apr-11 22:18
mentorWendelius1-Apr-11 22:18 
AnswerRe: Exception form HRESULT 0*800AC472 Pin
Abhinav S3-Apr-11 7:20
Abhinav S3-Apr-11 7:20 
QuestionNeed help w/ custom serialization (specifically OnSerializing attribute) [modified] Pin
SledgeHammer011-Apr-11 14:03
SledgeHammer011-Apr-11 14:03 
AnswerRe: Need help w/ custom serialization (specifically OnSerializing attribute) Pin
Dave Kreskowiak1-Apr-11 15:21
mveDave Kreskowiak1-Apr-11 15:21 
GeneralRe: Need help w/ custom serialization (specifically OnSerializing attribute) Pin
SledgeHammer011-Apr-11 15:47
SledgeHammer011-Apr-11 15:47 
GeneralRe: Need help w/ custom serialization (specifically OnSerializing attribute) Pin
Dave Kreskowiak1-Apr-11 17:10
mveDave Kreskowiak1-Apr-11 17:10 
GeneralRe: Need help w/ custom serialization (specifically OnSerializing attribute) Pin
SledgeHammer011-Apr-11 17:29
SledgeHammer011-Apr-11 17:29 
The collection I'm working on is derived from ObservableCollection<T>. That means I would need to implement ISerializable to basically mimic everything the .NET serialization does on *any* type of object and I'd spend the rest of my life trying to handle all the cases Frown | :( Not a good idea IMO.

BUT GOOD NEWS!!

After spending an hour or so in Reflector, I managed to find a little hole that I can cram myself into. Works with all the different serializers. Much easier solution then implementing ISerializable Smile | :) . NOTE: this is NOT a general / generic solution, I just wanted something to work automatically with my ObservableCollection<T> derived class and this is it.

ObservableCollection<T> is derived from Collection<T>. Collection<T> implements the ICollection interface.

What I found was, that somewhere deep in the bowels of .NET XML serialization, they special case ICollection and call the ICollection.Count getter very early on.

So all I did was implement ICollection in my class:

int ICollection.Count
{
get
{
LazyLoad();
return Count;
}
}

for ICollection.IsSyncronized, they simply return false, so I did the same.

ICollection.SyncRoot and ICollection.CopyTo, well, those are a bit trickier functions that I didn't really want to bother re-writing, so I just used reflection & expression trees to call the ones in Collection<T> Smile | :) .

And voila! Now my class will perform the lazyload automatically when its serialized.
GeneralRe: Need help w/ custom serialization (specifically OnSerializing attribute) Pin
Dave Kreskowiak2-Apr-11 2:16
mveDave Kreskowiak2-Apr-11 2:16 
Questiona little help on "most used" codes ! Pin
_Q12_1-Apr-11 11:44
_Q12_1-Apr-11 11:44 
AnswerRe: a little help on "most used" codes ! Pin
jschell1-Apr-11 12:03
jschell1-Apr-11 12:03 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_1-Apr-11 20:29
_Q12_1-Apr-11 20:29 
GeneralRe: a little help on "most used" codes ! Pin
jschell4-Apr-11 8:11
jschell4-Apr-11 8:11 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_4-Apr-11 18:40
_Q12_4-Apr-11 18:40 
GeneralRe: a little help on "most used" codes ! Pin
Michael900017-Apr-11 21:02
Michael900017-Apr-11 21:02 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_18-Apr-11 0:06
_Q12_18-Apr-11 0:06 
GeneralRe: a little help on "most used" codes ! Pin
Michael900018-Apr-11 12:16
Michael900018-Apr-11 12:16 
AnswerRe: a little help on "most used" codes ! Pin
PIEBALDconsult1-Apr-11 14:39
mvePIEBALDconsult1-Apr-11 14:39 
JokeRe: a little help on "most used" codes ! Pin
loyal ginger1-Apr-11 17:51
loyal ginger1-Apr-11 17:51 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_1-Apr-11 20:52
_Q12_1-Apr-11 20:52 
AnswerRe: a little help on "most used" codes ! Pin
Luc Pattyn1-Apr-11 16:31
sitebuilderLuc Pattyn1-Apr-11 16:31 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_1-Apr-11 21:12
_Q12_1-Apr-11 21:12 
AnswerRe: a little help on "most used" codes ! Pin
dan!sh 1-Apr-11 21:19
professional dan!sh 1-Apr-11 21:19 
GeneralRe: a little help on "most used" codes ! Pin
_Q12_1-Apr-11 21:36
_Q12_1-Apr-11 21:36 
GeneralRe: a little help on "most used" codes ! Pin
dan!sh 1-Apr-11 21:49
professional dan!sh 1-Apr-11 21:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.