Esempio n. 1
0
        public static void ExportXML(string path, string file)
        {
            using (var xml = new XmlDataStore <ConquestSerial, Conquest>(path, file))
            {
                xml.OnSerialize = doc =>
                {
                    XmlElement root = doc.CreateElement("Conquests");

                    foreach (Conquest conquest in xml.Values)
                    {
                        PropertyList <Conquest> pList = conquest.GetProperties(
                            BindingFlags.Instance | BindingFlags.Public,
                            p => p.CanWrite && p.Name != "Enabled" && p.Name != "InvokeReset" && p.Name != "InvokeClear");

                        XmlElement conquestNode = doc.CreateElement("Conquest");

                        conquestNode.SetAttribute("type", conquest.GetType().Name);

                        foreach (KeyValuePair <string, object> kv in pList.Where(kv => SimpleType.IsSimpleType(kv.Value))
                                 )
                        {
                            string flag;
                            string value;

                            if (SimpleType.IsSimpleType(kv.Value))
                            {
                                SimpleType sType = SimpleType.FromObject(kv.Value);

                                flag  = sType.Flag.ToString();
                                value = sType.Value.ToString();
                            }
                            else if (kv.Value is Type)
                            {
                                flag  = "Type";
                                value = ((Type)kv.Value).Name;
                            }
                            else if (kv.Value is ITypeSelectProperty)
                            {
                                flag  = "Type";
                                value = ((ITypeSelectProperty)kv.Value).TypeName ?? String.Empty;
                            }
                            else
                            {
                                continue;
                            }

                            XmlElement conquestPropNode = doc.CreateElement(kv.Key);

                            conquestPropNode.SetAttribute("type", flag);
                            conquestPropNode.SetAttribute("value", value);

                            conquestNode.AppendChild(conquestPropNode);
                        }

                        root.AppendChild(conquestNode);
                    }

                    doc.AppendChild(root);

                    return(true);
                };

                ConquestRegistry.CopyTo(xml, true);

                xml.Export();

                foreach (Exception e in xml.Errors)
                {
                    e.ToConsole();
                }
            }
        }
Esempio n. 2
0
 public bool CanHandle(Type plainNetType, out OpenTypeKind mapsTo, CanHandleDelegate canHandleNestedTypeCallback)
 {
     mapsTo = OpenTypeKind.SimpleType;
     return(SimpleType.IsSimpleType(plainNetType));
 }