Just like the question raised by his "waiting for nothing" on the fifth floor, there is a little problem with the code below,
XElement root = objects = obj root.Elements() obj;
If you copy the code of Liu Dongxia, it will not be able to read the data. I think it should be a ray that Liu Dongxia intentionally buried.
According to his article, I practiced it again:
First, several classes are created, one Person class, one Man class, and one Woman class. There are three classes in total. xml documents will be created based on these three classes;
Person:
Name { ; Sex { ; Eat( : Console.WriteLine(.Name + + person.Name + ); : Console.WriteLine(.Name + + person.Name + ); :
Man:
Man( name, .Name =.Sex =
Woman:
Woman( name, .Name =.Sex =
Next, we will create an xml document based on the above three classes (hand-written,
Object. xml:
Followed by the XmlFcatory class:
IDictionary<, > objectDefine = Dictionary<, > XmlFactory( InstanceObjects(= = ns + = objects = obj root.Elements(name) ==>=> typeName = v.Attribute(= GetObject( result = =
Finally, it is called at the entrance of the main program:
Program class:
Main( = XmlFactory(= ctx.GetObject() = = = ctx.GetObject() = = + +
This is a complete practice, but the error is slightly modified.
The modified code is as follows:
InstanceObjects(= = ns + = objects = obj root.Elements(name) ==> k.Attribute().Value, v => typeName = v.Attribute(=
In this way, data can be normally read.