简体   繁体   中英

storing a serializable object in the session

I have an object that I store in the session, something like this:

[Serializable]
public class GoyaAppUserServerSession
{
   public int TheInt{ get; set; }
   public string TheString{ get; set; }
   public byte TheByte{ get; set; }

   public void SomeMethod() { ... }
   public void SomeOtherMethod() { ... }
}

My server session has 3 values and 2 methods. When the object is serialized and deserialized, does the serialization only apply to the values, in which case it's negligible, or is the code that's inside the methods also serialized as a string?

Thanks.

Only the values; since methods are a compiled definition of the class, there is no reason to store these; therefore it only stores the values of the properties. Depending on what you are serializing with, it usually uses the properties as the names of the fields during the serialization process. For instance, if you use XML, it would use the property name as attribute or element, and the value as the inner content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM