How to serialize shared members of a class?
-
I want to binary serialize a class, which has only shared items (variables & objects of different types) which I use globally in my code. When I want to serialize it, I get the error "'EmailAccount' is a type and cannot be used as an expression" :
binformatter.Serialize(filstream, EmailAccount)
I even tried to create an object from the class and serialize it. But it seems to only save the instance variables and not the shared ones. Is there a way to serialize them? -
I want to binary serialize a class, which has only shared items (variables & objects of different types) which I use globally in my code. When I want to serialize it, I get the error "'EmailAccount' is a type and cannot be used as an expression" :
binformatter.Serialize(filstream, EmailAccount)
I even tried to create an object from the class and serialize it. But it seems to only save the instance variables and not the shared ones. Is there a way to serialize them?Serialzation only works on instance members. Shared, or static in C#, members are not part of any instance. You'll have to either save them sepearately or there are various methods of including the static members in the serialization, but they will be included in every single instance of the class you serialize. One method would be to create public "wrapper" properties for the shared members.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...