XML serialization This thing is quite people. When your class is so, when serialization, when you are serialization,
XmlSerializer Serialize = New XMLSerializer (TypeOf (MyClass));
This sentence will come out of a "reflection type error" error. In fact, that ishtable is in the ghost, directly put the above sentence.
XMLSerializer Serialize = New XmlSerializer (TypeOf (HashTable);
The culprit came out. This time is: "Does not support type system.collections.hashtable because it implements idictionary. There are still some special requirements for the collection class when XML serialization.
Let's first look at a collection class with normal sequence -Araylist:
Serialize = New XMLSERIALIZER (TypeOf (ArrayList);
The following statement can be found in the document that temporarily generated during the serialization process:
WriteStartElement (@ "arrayofanytype", @ "");
For (int = 0; IA IA ) { Write1_object (@ "anytype", @ ", ((System.Object) a [Ia]), true, false; } WriteEndelement (); For the collection class, it is necessary to write XML as described above in the XML serialization process. Because Item attributes (that is, C # in [], it is called an indexer, and the name is not a bit messy: [C #] Object this [ Object Key ] {GET; SET;} Object this [ Object Key ] {GET; SET; The above is the result of the results. When the final sequence is seized, the collection class is serialized in the loop mode above, and the class that implements the idictionary interface is uncommon, so it is generated in the generation of temporary files. When it is not letting it generate, the DLL that is generated anyway is also unable to run, and it is straightforward. In fact, it can be found on the SDK, there is such a paragraph about XML serialization: XMLSerializer can process classes that implement IENUMERABLE or ICOLLECTION in different ways (the conditions are these classes to meet certain requirements). A class that implements the IEnumerable must implement a public add method with a single parameter. The parameters of the Add method must match the type returned from the IEnumerator.Current property returned from the GetEnumerator method (polymorphism). In addition to implementing IEnumerable classes (such as CollectionBase) must have a common Item index property (in C # is an indexer), and it must have an integer type public Count property. Parameters passing to the ADD method must be the same as the type returned from the ITEM property, or the same as a certain type of this type. For classes that implement ICOLLECTION, the serialized value will be retrieved from the index item attribute instead of calling getenumerator. Also note that the public field and attribute will not serialize in addition to the public fields returned to another set class (implementation of ICollection's collection class). Unable to meet the above conditions, the corresponding exception is thrown, and the class that implements the iDictionary interface is clearly unable to satisfy. When the .NET is implemented, it is determined that the iDictionary interface will be determined, and the interface is found. Directly, what add-on method, Item attribute, no matter what the ITEM attribute. Another point, that is L - class (Class level) - including collection classes and non-collections, l Non-collective classes require access to sequential properties (without serialized attribute exceptions), l In the collection class, the add method, item attribute, count property, the access method of the Current property, etc. above mentioned above. If there is a SECURITTRIBUTE statement, it is not sequenceless. However, now the code is that SECURITTRIBUTE is very little - this aspect is in the practice of painting in practice, in practice. To serialize the HashTable is actually just a few integer type of item properties, there is no way on this. Thinking that SortedList is much different from HashTable, but it can also sequentially obtain the elements in the collection, just use the Item property that is not integer type, but use the getByIndex () method. So use it to steal the column. Item is a custom class. There is nothing specific. Item is a custom class. There is nothing specific. // [securityAction.assert] Public class mycollection: iCollection { Private sortedlist list = new sortedlist (); PUBLIC mycollection () { } // [securityAction.assert] Public void add (item item) { List.add (item.id, item); } Public item this [int index] { Get {return (item) list.getbyindex (index); } Icollection member #Region iCollection Public bool issynchronized { Get { Return False; } } Public int count { Get {return list.count; } } [ENVIRONMENTPERMISSION (SecurityAction.Assert)] Public void copyto (array arrrey, int index) { List.copyto (array, index); } Public Object syncroot { Get { Return this; } } #ndregion Ienumerable member #Region Ienumerable member Public ienumerator getenumerator () { Return list.GeteNumerator (); } #ndregion } That way, this MyCollection class can be serialized, then put the sortedlist other attribute package, it is basically used as a sortedlist, saying that it is HashTable. However, limitations are still there. Its Add method parameters, the type of Item attribute must be strong, and cannot use Objcet. With object type, temporary files can be generated, serialize = new xmlserializer (Typeof (MyClass)); this sentence can be made by no abnormal. But when you really serialize, unless some basic data types, otherwise it doesn't know how to write that type into the corresponding string, write XML files wrong.