c# - Avoid Using Class don't Support Serializable -


everyone:

i viewed way of avoiding using class don't support serializable. don't know reason of using method. posed question here.

so previous code likes following

    [serializable]     class outterclass     {         public usingclass usingclassmember         {             get;             set;         }     } 

so here, if want serialize outterclass, occur exception because usingclass don't support serializing. obviously, members in outterclass should support serializing if want serialize outterclass.

but if modify code following. serialize operation can done successfully.

    [serializable]     class outterclass     {         [nonserialized]         private usingclass m_usingclassmember;         public usingclass usingclassmember         {             { return m_usingclassmember; };             set { m_usingclassmember = value };         }     } 

i don't know reason of modification. seems property usingclassmember's serialization don't need serialize class usingclass itself. can give me explanation?

thanks!

you have example of how prevent c# auto property serialization.

attribute 'nonserialized' not valid on declaration type. valid on 'field' declarations.

so can't set 'nonserialized' on c# auto property if property baking field second example can set did. both property , field not serialized.

in second case compiler ignore property because underline field non serialized , not exception first case.

if want serialize have set serializable property on usingclass if don't need serialize can second method or using [xmlignoreattribute] on auto property


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -