开发者

session: going from InProc to SQL session

I'm switching from InProc session to SQL server session. Currently, my session object looks like this:

public class UserSession{

  public string TheStrings {get;set;}
  public int TheInts {get;set;}

  public List<MyObjectModel> ListOfObjects {get;set;}

}

It basically holds strings, ints and several lists of objects. What I do is store this object in the session and then when I need to access the session, I can write Us开发者_JAVA技巧erSession.TheStrings.

Now that I'm cconverting this to SQL session, serialization comes in play. Do I need to add the [serializable] attribute only to the entire class or do I also need to add it to the class definition of all the MyObjectModels as well?

Thanks.


I am pretty sure it will serialize by default as long as everything in your objects are simple types.

SerializableAttribute Class

Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. The common language runtime throws SerializationException if any type in the graph of objects being serialized does not have the SerializableAttribute attribute applied.

Apply the SerializableAttribute attribute even if the class also implements the ISerializable interface to control the serialization process.

All the public and private fields in a type that are marked by the SerializableAttribute are serialized by default, unless the type implements the ISerializable interface to override the serialization process. The default serialization process excludes fields that are marked with the NonSerializedAttribute attribute. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the NonSerializedAttribute attribute to that field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜