gpt4 book ai didi

asp.net - 我们可以将哪些类型的对象置于 View 状态?

转载 作者:行者123 更新时间:2023-12-04 17:05:10 25 4
gpt4 key购买 nike

我想知道为什么我们必须设置可序列化属性才能将对象保存在 View 状态。

另外,我们可以在 View 状态中存储哪种类型的对象?

最佳答案

ViewState使用 ObjectStateFormatter 使用二进制序列化进行序列化.从文档中引用:

The ObjectStateFormatter class is optimized to serialize and format many common .NET Framework reference types, as well as constants. The following table lists the types that are optimized.

Array, DateTime, Int16, String, ArrayList, Double, Int32, String [], Boolean, Enum, null (Nothing), String.Empty, Byte, Hashtable, Pair, Triplet, Char, HybridDictionary, Single, Type, Color, IDictionary,

Additionally, while conventional string types and string arrays are written to and from a serialized binary writer unaltered, some strings are optimized by creating internal string tables. Strings are optimized using these tables if the string has an associated TypeConverter object or if the string is actually an instance of the IndexedString class.

Other types not listed above are binary-serialized using a BinaryFormatter object if they implement the ISerializable interface or are decorated with the SerializableAttribute attribute. The ObjectStateFormatter class is not optimized for any of these serializable types.

If the ObjectStateFormatter class encounters a type that is not serializable, an ArgumentException exception is thrown.



对于要在 ViewState 中进行二进制序列化的对象它需要用 [Serializable] 装饰属性。所以你可以输入 ViewState任何具有此属性的对象。请注意,字符串、整数、浮点数等简单类型也可以放在 ViewState 中。 .

关于asp.net - 我们可以将哪些类型的对象置于 View 状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3583573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com