refers: http://msdn.microsoft.com/en-us/magazine/cc301761.aspx
Serialization is the process of converting an object or a connected graph of objects into a contiguous stream of bytes. Deserialization is the process of converting a contiguous stream of bytes back into its graph of connected object.
How serialization works:
1.1) If any fields in the graph refer to other objects, then it serialize these objects, too. In other words, it is convenient to implement deep clone using serialization and deserialization.
1.2) If two objects in the graph refer to each other, then the formatter detects this, serializes each object just once, and avoids entering into an infinite loop.
1.3) It is possible and also quite useful to serialize multiple object graphs out to a single byte stream.
1.4) When serializing an object, the full name of the type and the name of the type's defining assembly are written to the byte stream. By default, the BinaryFormatter and SoapFormatter types output the assembly's full identity, which includes the assembly's file name (without extension), version number, culture, and public key information
1.5) Whole Process
a.1) MemberInfo[] GetSerializableMembers(Type type);
a.2) Object[] GetObjectData(Object obj, MemberInfo[] members);
a.3) write the assembly type info and 2 arrays into the stream.
b.1) Type GetTypeFromAssembly(Assembly assem, String name);
b.2) Object GetUninitializedObject(Type type); It does not call any constructor.
b.3) MemberInfo[] GetSerializableMembers(Type type);
b.4) Object PopulateObjectMembers(Object obj, MemberInfo[] members, Object[] data);
Dev notes:
2.1) By default, types are not serializable. developer must apply the System.SerializableAttribute custom attribute to this type, to make it serializable.
2.2) For performance reasons, formatters do not verify that all of the objects in the graph are serializable before serializing the graph. So, when serializing an object graph, it is entirely possible that some objects may be serialized to the byte stream before the SerializationException is thrown. If this happens, the byte stream is corrupt.
I recommend that you serialize the objects into a MemoryStream first. Then, if all objects are successfully serialized, you can copy the bytes in the MemoryStream to whatever stream (file or network, for example) you really want the bytes written to.
2.3) The SerializableAttribute custom attribute may be applied to reference types (class), value types (struct), enumerated types (enum), and delegate types (delegate) only
2.4) You can easily make a derived class to be serializable if the base class is serializable. But if the base class is not, then you cannot apply the Serializable attribute to the derived class.
2.5) So you may want to make all your classes serializable to grant a lot of flexibility to users of your types. However, you must be aware that serialization reads all of an object's fields regardless of whether the fields are declared as public, protected, internal, or private.
2.6) You can put NonSerializedAttribute to a type's fields, so the fields are ignored when serializing. And the attribute continues to apply to these fields when inherited by another type.
You may need to implement the System.Runtime.Serialization.IDeserializationCalback interface, if you need to do something for those NonSerialized fields.
During deserialization, formatters check to see if the object it is deserializing comes from a type that implements the IDeserializationCallback interface. If the type does implement this interface, then the formatter adds this object's reference to an internal list. After all of the objects have been deserialized, the formatter walks this list and calls each object's OnDeserialization method.
Thursday, December 4, 2008
知识更新没有那么可怕。It's your worktime fun.
成为一个技术高手,不需要头悬梁锥刺股,也不需要废寝忘食。需要做的只是合理利用你的上班时间。
刚毕业的时候,看过一篇文章, 大体意思如下:(可惜找不到原文了 )
大学生刚毕业的时候都是站在同一条起跑线上(都是什么都不会),等过上3-5年,差别就显出来了,为什么?因为大家每天上班的8个小时都差别不大,都是为了挣一份工资养活自己;但是不同的是除了睡觉之外的其余8个小时,如何利用这些业余时间使得这些社会新鲜人在3-5年内产生了很大的差异。这就是所谓的8小时求生存,8小时求发展。
当时觉得这篇文章说得很对,于是决定好好利用业余时间读技术书,成为一名技术高手。但是在丢掉了学生时代晚自习的习惯之后,想要在晚上读严肃一点的书都会马上起到催眠的效果。结果书也没有读完一两本(技术书都太厚了。。。)。
到了现在的公司不久,领导教育我说,很多人在刚进公司的时候,水平都差不多,但是过了2年以后,有的人原地不动,有的人技术提高很多,为什么呢?(咦,怎么听上去这么熟悉呢?)那么为什么呢?因为有的人会很好的利用Slow time,在这段时间内好好充实自己;而有的人在Slow time就晚来早走,一天在公司也就呆4,5个小时,中间还要来一个长长的午餐,剩下的时间也就上网看看新闻,看看YouTube,聊聊天。
这个说法听上去很有道理,而且很具有可操作性。但是,有一点很重要的他没有提到。一般在Busy time的时候,干的活儿很多,遇到的不懂的技术点也就很多,但是没有时间仔细去研究,只求快点把事情做完。而闲下来的时候,又一时不知道该学点什么,没有边际的学习其实是效果很差的。
所以呢,我就开始保留一个Study List, 每次遇到自己不懂的又想了解清楚的技术点时候,就把它列进去,然后等不太忙的时候再拿出这个列表选一个最想学的去学。
再就是这个列表解决的另一个问题,就是在学习知识A的过程中遇到了知识B,于是去学B,又遇到了C,最后发现自己不懂的东西太多,都忘记自己最初要学的是什么了,只能很郁闷的放弃。用数据结构的语言来讲,这就是树的深度遍历遇到的问题,那么我们只需要采用广度遍历,学习A的时候,遇到B,那么把B放到我们的Study List里面,继续学习A. 学完A了再考虑学B,这个令人沮丧的问题就迎刃而解了。
一个圆的面积越大,那么它的周长所能接触的面积也就越大。假使圆的面积是“知道”,圆外面的世界是“无知”;那么一旦我们“知道”得越多,我们也就相对地越是“无知”。但是我们有了Study List这个利器,就不会迷失在学而无涯的迷茫中。 ^_^
=============================
我的Study List:
1) XML
a. Structed knowledge
b. Sql & xml
c. XmlTextReader, XmlTextWriter vs XmlDocument
d. Namespace?
2) Serialization
3) Delegate type
4) XPath
5) XSLT
a. Xslt parameter (how to pass)
b. Xslt function
c. DataSet & xsl
6) SOAP
7) Design Patterns
8) C# image process
9) ASP.net 2.0 AJAX
http://ajax.asp.net/docs/default.aspx
10) IIS
11) Regular Expression
12) System tables in SQL
13) SQL: Indexes and performance
刚毕业的时候,看过一篇文章, 大体意思如下:(可惜找不到原文了 )
大学生刚毕业的时候都是站在同一条起跑线上(都是什么都不会),等过上3-5年,差别就显出来了,为什么?因为大家每天上班的8个小时都差别不大,都是为了挣一份工资养活自己;但是不同的是除了睡觉之外的其余8个小时,如何利用这些业余时间使得这些社会新鲜人在3-5年内产生了很大的差异。这就是所谓的8小时求生存,8小时求发展。
当时觉得这篇文章说得很对,于是决定好好利用业余时间读技术书,成为一名技术高手。但是在丢掉了学生时代晚自习的习惯之后,想要在晚上读严肃一点的书都会马上起到催眠的效果。结果书也没有读完一两本(技术书都太厚了。。。)。
到了现在的公司不久,领导教育我说,很多人在刚进公司的时候,水平都差不多,但是过了2年以后,有的人原地不动,有的人技术提高很多,为什么呢?(咦,怎么听上去这么熟悉呢?)那么为什么呢?因为有的人会很好的利用Slow time,在这段时间内好好充实自己;而有的人在Slow time就晚来早走,一天在公司也就呆4,5个小时,中间还要来一个长长的午餐,剩下的时间也就上网看看新闻,看看YouTube,聊聊天。
这个说法听上去很有道理,而且很具有可操作性。但是,有一点很重要的他没有提到。一般在Busy time的时候,干的活儿很多,遇到的不懂的技术点也就很多,但是没有时间仔细去研究,只求快点把事情做完。而闲下来的时候,又一时不知道该学点什么,没有边际的学习其实是效果很差的。
所以呢,我就开始保留一个Study List, 每次遇到自己不懂的又想了解清楚的技术点时候,就把它列进去,然后等不太忙的时候再拿出这个列表选一个最想学的去学。
再就是这个列表解决的另一个问题,就是在学习知识A的过程中遇到了知识B,于是去学B,又遇到了C,最后发现自己不懂的东西太多,都忘记自己最初要学的是什么了,只能很郁闷的放弃。用数据结构的语言来讲,这就是树的深度遍历遇到的问题,那么我们只需要采用广度遍历,学习A的时候,遇到B,那么把B放到我们的Study List里面,继续学习A. 学完A了再考虑学B,这个令人沮丧的问题就迎刃而解了。
一个圆的面积越大,那么它的周长所能接触的面积也就越大。假使圆的面积是“知道”,圆外面的世界是“无知”;那么一旦我们“知道”得越多,我们也就相对地越是“无知”。但是我们有了Study List这个利器,就不会迷失在学而无涯的迷茫中。 ^_^
=============================
我的Study List:
1) XML
a. Structed knowledge
b. Sql & xml
c. XmlTextReader, XmlTextWriter vs XmlDocument
d. Namespace?
2) Serialization
3) Delegate type
4) XPath
5) XSLT
a. Xslt parameter (how to pass)
b. Xslt function
c. DataSet & xsl
6) SOAP
7) Design Patterns
8) C# image process
9) ASP.net 2.0 AJAX
http://ajax.asp.net/docs/default.aspx
10) IIS
11) Regular Expression
12) System tables in SQL
13) SQL: Indexes and performance
Sunday, November 23, 2008
Bike to work
Last week is bike to work week (winter version), and I rode the whole week. It was amazing that we had a whole week without rain in winter in Vancouver, perfect weather for riding. :)
I started to ride to work since last year, and it was May to October. I caught a cold at the beginning of October, and stopped riding since then.
For this year, I started riding from the end of March. Later I got all my rain gears (waterproof pants, jacket, shoe covers, reflectors...), which make me I could ride in the rainy days. I caught a cold again in the beginning of this October, I stopped riding for a couple of days, but I go back to ride as soon as I recovered. At the beginning of Nov, I heard that the VACC announced the Bike to work winter version, and I thought they were crazy. I never imaged I could still ride in the end of Nov.
Gain(Loss) from this year's riding:
1) Weight Loss of 6.5 pounds
2) Saved the money for ~7 month passes (~ $500, wow!). Minus the money spend on the rain gears, still saved ~$300 :)
Well, good enough. I guess I'll stop riding for Dec, Jan and Feb. I have already seen frost last week, and I can expect to see some ice in the next couple of days. Snow or Ice, that are the stop signs for me.
I started to ride to work since last year, and it was May to October. I caught a cold at the beginning of October, and stopped riding since then.
For this year, I started riding from the end of March. Later I got all my rain gears (waterproof pants, jacket, shoe covers, reflectors...), which make me I could ride in the rainy days. I caught a cold again in the beginning of this October, I stopped riding for a couple of days, but I go back to ride as soon as I recovered. At the beginning of Nov, I heard that the VACC announced the Bike to work winter version, and I thought they were crazy. I never imaged I could still ride in the end of Nov.
Gain(Loss) from this year's riding:
1) Weight Loss of 6.5 pounds
2) Saved the money for ~7 month passes (~ $500, wow!). Minus the money spend on the rain gears, still saved ~$300 :)
Well, good enough. I guess I'll stop riding for Dec, Jan and Feb. I have already seen frost last week, and I can expect to see some ice in the next couple of days. Snow or Ice, that are the stop signs for me.
Sunday, November 9, 2008
** is my middle name
** is my middle name, 这种表达法在电视广告的轰炸下,终于被我深深的记住了,表示**是我最大的特征或者最喜欢做的事。比如:Cool is my middle name. Danger is my middle name.
我们公司有一个同事(假设他叫Eric Cartman),特喜欢跟别人开玩笑。别人说他你怎么总是harass people? 然后他就得意洋洋的说"Harass is my middle name." 这样听他说了几次,也没觉得有多搞笑。直到有一天,他再次说"Harass is my middle name"的时候,另一个同事说,我明白了,原来你的全名叫Eric Harass(es) Cartman.
^_^
我们公司有一个同事(假设他叫Eric Cartman),特喜欢跟别人开玩笑。别人说他你怎么总是harass people? 然后他就得意洋洋的说"Harass is my middle name." 这样听他说了几次,也没觉得有多搞笑。直到有一天,他再次说"Harass is my middle name"的时候,另一个同事说,我明白了,原来你的全名叫Eric Harass(es) Cartman.
^_^
股市大跌影响流浪汉的收入
在温哥华的流浪汉聚居的区域走过,看到一个流浪汉在追着一个黑人要钱。黑人说“I don't have money!” 而后,似乎嫌语气还不够强烈似的,说“I lost all my money in the stock market!”
Wednesday, October 15, 2008
火鸡节过后的经济形势
昨天是火鸡节后的第一个工作日。Ok,我知道那是Thanksgiving感恩节,不过鉴于月饼节听上去比中秋节更加生动形象,那感恩节也就该具体化为火鸡节了。
言归正传。一个从来都是吃外卖午饭的同事破天荒带了午饭,于是大家说看来经济形势真的是不好了。但是事实上,他只是前一天家里烤了一只大火鸡,没吃完,所以才带过来当午饭。。。
言归正传。一个从来都是吃外卖午饭的同事破天荒带了午饭,于是大家说看来经济形势真的是不好了。但是事实上,他只是前一天家里烤了一只大火鸡,没吃完,所以才带过来当午饭。。。
Subscribe to:
Posts (Atom)