Content Pipeline:

- XmlImporter is now able to import simple xml files without lists or dictionary and stuff, but its not stable yet
This commit is contained in:
SND\eagleeyestudios_cp 2012-10-02 20:05:12 +00:00 committed by Konstantin Koch
parent 07b67d4565
commit 939ec9e719

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Xml; using System.Xml;
using ANX.Framework.Content.Pipeline.Serialization; using ANX.Framework.Content.Pipeline.Serialization;
@ -102,7 +104,7 @@ namespace ANX.Framework.Content.Pipeline.Importer
} }
else else
{ {
if (reader.Name == "Item" && reader.NodeType == XmlNodeType.Element) /* if (reader.Name == "Item" && reader.NodeType == XmlNodeType.Element)
{ {
if (!isDict) if (!isDict)
{ {
@ -114,27 +116,43 @@ namespace ANX.Framework.Content.Pipeline.Importer
reader.ReadStartElement(); reader.ReadStartElement();
var key = reader.ReadContentAsString(); var key = reader.ReadContentAsString();
reader.ReadEndElement(); reader.ReadEndElement();
var typeBlah = ResolveType(attrib); var typeBlah = ResolveType(attrib); //TODO: Reading type attributes does not work! Think of a solution!
var value = reader.ReadContentAs(typeBlah, null); var value = reader.ReadContentAs(typeBlah, null);
reader.ReadEndElement(); reader.ReadEndElement();
dict.Add(key, value); dict.Add(key, value);
} }*/
if (reader.NodeType == XmlNodeType.Attribute && reader.Name == "Type") //if (reader.NodeType == XmlNodeType.Attribute && reader.Name == "Type")
attrib = reader.ReadContentAsString(); // attrib = reader.ReadContentAsString();
} }
lastNode = reader.Name; lastNode = reader.Name;
reader.Read(); reader.Read();
} }
System.Diagnostics.Debugger.Break(); //Debugger.Break();
//TODO: Get all public properties of the class via reflection //TODO: Get all public properties of the class via reflection
//Activate instance //Activate instance
var result = Activator.CreateInstance(type); var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
var result = constructors[0].Invoke(new object[] {});
//TODO: Check if there is a pendant for every entry
//TODO: Match every property with its value //TODO: Match every property with its value
var properties = type.GetFields(BindingFlags.Instance | BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Public);
foreach (var property in properties)
{
var attribs = property.GetCustomAttributes(typeof (ContentSerializerAttribute), true);
if (attribs.Length == 0)
continue;
if (props.ContainsKey(((ContentSerializerAttribute)attribs[0]).ElementName))
{
property.SetValue(result, props[((ContentSerializerAttribute)attribs[0]).ElementName]);
props.Remove(((ContentSerializerAttribute)attribs[0]).ElementName);
}
}
if (props.Count > 0)
{
logger.LogWarning("", null, "There are unset properties left!", result);
Debugger.Break();
}
//Return the whole construct //Return the whole construct
return result; return result;