最近我有這個問題,並有解構存儲狀態investigate a performance issue;粗略的代碼是這樣的:
byte[] blob = ... // TODO
using (var ms = new MemoryStream(blob))
using (BinaryReader reader = new BinaryReader(ms)) {
int len = reader.ReadInt32();
bool f1 = reader.ReadBoolean(), f2 = reader.ReadBoolean();
SessionStateItemCollection items = null;
HttpStaticObjectsCollection sitems = null;
if (f1) {
items = SessionStateItemCollection.Deserialize(reader);
}
if (f2) {
sitems = HttpStaticObjectsCollection.Deserialize(reader);
}
if (reader.ReadByte() != 0xFF) {
throw new InvalidOperationException("corrupt");
}
if (items != null) {
int max = items.Count;
for (int i = 0; i < max; i++) {
object obj = items[i];
Console.WriteLine("{0}\t{1}", items.Keys[i],
obj == null ? "n/a" : obj.GetType().FullName);
}
}
}
你剛剛爲我節省了很多時間(試圖從數據庫中解擾一些BLOB);謝謝。 – 2009-11-13 13:56:22