コード例 #1
0
ファイル: Condition.cs プロジェクト: zerodowned/UO-Forever
        public static string Sanitize(object value)
        {
            var s = SimpleType.FromObject(value);

            return(s.ToString());
        }
コード例 #2
0
ファイル: SerializeExt.cs プロジェクト: zerodowned/UO-Forever
 public static void WriteSimpleType(this GenericWriter writer, object obj)
 {
     SimpleType.FromObject(obj).Serialize(writer);
 }
コード例 #3
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();
                }
            }
        }