Пример #1
0
    /// <summary>
    /// 将xml转换为二进制
    /// </summary>
    /// <param name="className"></param>
    public static void XmlToBinary(string className)
    {
        if (string.IsNullOrEmpty(className))
        {
            return;
        }
        try
        {
            Type type = null;
            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type tempType = asm.GetType(className);
                if (tempType != null)
                {
                    type = tempType;
                    break;
                }
            }

            if (type != null)
            {
                string xmlPath    = XMLPATH + className + ".xml";
                string binaryPath = BINARYPATH + className + ".bytes";
                object obj        = BinarySerializeOpt.XmlDeserialization(xmlPath, type);
                BinarySerializeOpt.BinarySerialize(binaryPath, obj);
                Debug.Log(className + "xml转二进制成功!");
            }
        }
        catch (Exception e)
        {
            Debug.LogError(className + "xml转二进制失败!" + e);
        }
    }
Пример #2
0
 static void XmlToBinary(string name)
 {
     try
     {
         Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
         Type       type       = null;
         foreach (Assembly assembly in assemblies)
         {
             type = assembly.GetType(name);
             if (type != null)
             {
                 break;
             }
         }
         if (type != null)
         {
             string xmlPath    = XML_DATA_PATH + name + ".xml";
             object obj        = BinarySerializeOpt.XmlDeserialize(type, xmlPath);
             string binaryPath = BINARY_DATA_PATH + name + ".bytes";
             BinarySerializeOpt.BinarySerialize(binaryPath, obj);
             Debug.Log("Xml转Binary成功 path:" + binaryPath);
         }
     }
     catch (System.Exception)
     {
         Debug.LogError("XmlToBinary 转换失败 name:" + name);
     }
 }