当前位置: 首页>>代码示例>>C#>>正文


C# XmlSerializer.Serialize方法代码示例

本文整理汇总了C#中XmlSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer.Serialize方法的具体用法?C# XmlSerializer.Serialize怎么用?C# XmlSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlSerializer的用法示例。


在下文中一共展示了XmlSerializer.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateItem

	public void CreateItem () {
		ItemContainer itemContainer = new ItemContainer ();

		Type[] itemTypes = { typeof(Equipment), typeof(Weapon), typeof(Consumeable)};
		FileStream fs = new FileStream (Path.Combine (Application.streamingAssetsPath, "Items.xml"), FileMode.Open);
		XmlSerializer serializer = new XmlSerializer (typeof(ItemContainer), itemTypes);
		itemContainer = (ItemContainer)serializer.Deserialize (fs);
		serializer.Serialize (fs, itemContainer);	 
		fs.Close ();

		switch (category) {
			case Category.EQUIPMENT:
			itemContainer.Equipment.Add(new Equipment(itemName, description, itemType, quality, spriteNeutral, spriteHighlighted, maxSize, intellect, agility, stamina, strength));
				break;
			case Category.WEAPON:
			itemContainer.Weapons.Add(new Weapon(itemName, description, itemType, quality, spriteNeutral, spriteHighlighted, maxSize, intellect, agility, stamina, strength, attackSpeed));
				break;
			case Category.CONSUMEABLE:
			    itemContainer.Consumable.Add(new Consumeable(itemName, description, itemType, quality, spriteNeutral, spriteHighlighted, maxSize, health, mana, rage));
				break;
        }

		fs = new FileStream (Path.Combine (Application.streamingAssetsPath, "Items.xml"), FileMode.Create); 
		serializer.Serialize (fs, itemContainer);
		fs.Close ();
	}
开发者ID:Fahrettin52,项目名称:Game-Lab-1.1,代码行数:26,代码来源:ItemManager.cs

示例2: Main

	static int Main ()
	{
		Foo foo = new Foo ();
		foo.Test = "BAR";
		foo.NullableInt = 10;

		XmlSerializer serializer = new XmlSerializer (typeof (Foo));

		MemoryStream stream = new MemoryStream ();

		serializer.Serialize (stream, foo);
		stream.Position = 0;
		foo = (Foo) serializer.Deserialize (stream);

		if (foo.Test != "BAR")
			return 1;
		if (foo.NullableInt != 10)
			return 2;

		foo.NullableInt = null;
		stream = new MemoryStream ();
		serializer.Serialize (stream, foo);
		stream.Position = 0;
		foo = (Foo) serializer.Deserialize (stream);

		if (foo.Test != "BAR")
			return 3;
		if (foo.NullableInt != null)
			return 4;

		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:32,代码来源:test.cs

示例3: Save

    public static void Save()
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List<Level>));

        using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsEasy.xml"), FileMode.Create)) serializer.Serialize(stream, easyLevels);
        using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsMedium.xml"), FileMode.Create)) serializer.Serialize(stream, mediumLevels);
        using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsHard.xml"), FileMode.Create)) serializer.Serialize(stream, hardLevels);
    }
开发者ID:mengtest,项目名称:Sudoku,代码行数:8,代码来源:LevelManager.cs

示例4: DictionaryElementIsRedacted

        public void DictionaryElementIsRedacted()
        {
            var instance = new RedactTestClassForXmlElement
            {
                Map = new Dictionary<int, string>
                {
                    { 1, "1abc" },
                    { 2, "d2ef" },
                    { 3, "gh3i" },
                    { 4, "jkl4" },
                }
            };
            var serializer = new XmlSerializer<RedactTestClassForXmlElement>();

            var xml = serializer.Serialize(instance);

            Assert.That(xml, Contains.Substring("<Key>1</Key>"));
            Assert.That(xml, Contains.Substring("<Key>2</Key>"));
            Assert.That(xml, Contains.Substring("<Key>3</Key>"));
            Assert.That(xml, Contains.Substring("<Key>4</Key>"));
            Assert.That(xml, Contains.Substring("<Value>1XXX</Value>"));
            Assert.That(xml, Contains.Substring("<Value>X1XX</Value>"));
            Assert.That(xml, Contains.Substring("<Value>XX1X</Value>"));
            Assert.That(xml, Contains.Substring("<Value>XXX1</Value>"));
        }
开发者ID:JonOsment,项目名称:XSerializer,代码行数:25,代码来源:RedactTestsForXmlElements.cs

示例5: Save

 public void Save(string FileName = "GameData.xml")
 {
      XmlSerializer Serializer = new XmlSerializer(typeof(GameStateData));
      FileStream FStream = new FileStream(FileName, FileMode.Create);
      Serializer.Serialize(FStream, GameState);
      FStream.Close();
 }
开发者ID:pmer,项目名称:zombie-ninja-attack-craft,代码行数:7,代码来源:LoadAndSaveManager.cs

示例6: SaveLevel

    public static void SaveLevel()
    {
        string m_path="Assets/Resources";
        string name= Creator.creator.SceneName+".xml";
        Encoding encoding = Encoding.GetEncoding("UTF-8");
        StreamWriter fout = new StreamWriter(m_path + "/" + name, false, encoding);
        MemoryStream stream=new MemoryStream();
        LevelObjectsInfo objects=new LevelObjectsInfo();
        objects.objectsInfo=EditorAdditionalGUI.EditorOptions.Objects.ConvertAll<CustomObjectInfo>(x=>x.SerializeObject());
        objects.info=EditorAdditionalGUI.EditorOptions.levels.ConvertAll<LevelInfo>(x=>x.SerializeLevel());
        objects.name=Creator.creator.SceneName;
        objects.defaultPortal=Creator.creator.defaultPortal.ObjectID;
        objects.mainTexture=Camera.main.GetComponent<CameraControls>().BackgroundTexture.GetComponent<Renderer>().sharedMaterial.mainTexture.name;
        System.Type[] types=new System.Type[EditorAdditionalGUI.EditorOptions.prefabs.Count+1];
        for(int i=0; i<EditorAdditionalGUI.EditorOptions.prefabs.Count; i++)
        {
            types[i]=EditorAdditionalGUI.EditorOptions.prefabs[i].GetComponent<CustomObject>().SerializedType();
        }
        types[EditorAdditionalGUI.EditorOptions.prefabs.Count]=typeof(LevelInfo);
        XmlSerializer serializer=new XmlSerializer(typeof(LevelObjectsInfo), types);
        //XmlTextWriter writer=new XmlTextWriter(stream, Encoding.UTF8);
        serializer.Serialize(fout, objects);
        //Debug.Log(stream.Length);

        //fout.Write(stream);
        fout.Close();
        AssetDatabase.Refresh();

        //EditorUtility.SetDirty();
    }
开发者ID:crassus0,项目名称:Edge-drivers,代码行数:30,代码来源:CreatorEditor.cs

示例7: WriteDust

 public void WriteDust(string path)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(ScriptDustItemsContainer));
         FileStream stream = new FileStream(path, FileMode.Create);
         serializer.Serialize(stream, this);
         stream.Close();
 }
开发者ID:noctisyounis,项目名称:Playground2015_Project2,代码行数:7,代码来源:ScriptDustItemsContainer.cs

示例8: CreateNewWindow

    /// <summary>
    /// Creates a new window with the given window ID and the current window UI
    /// </summary>
    public void CreateNewWindow(int windowID)
    {
        if (!Directory.Exists(Application.persistentDataPath + "/Windows")) {
            Directory.CreateDirectory(Application.persistentDataPath + "/Windows/");
        }

        string path = Application.persistentDataPath;
        if (windowID == -1)
            path += "/Windows/BaseWindow.txt";
        else
            path += "/Windows/Window" + windowID.ToString() + ".txt";
        try {
            myData = new WindowData();
            myData.windowID = windowID;

            using (FileStream fs = new FileStream(path, FileMode.Create)) {
                XmlSerializer xmls = new XmlSerializer(typeof(WindowData));
                xmls.Serialize(fs, myData);
                fs.Close();
            }

            Debug.Log ("Succesfully wrote UIWindow to " + path);
        } catch (InvalidOperationException e) {
            Debug.LogError ("Failed to write UIWindow to " + path + "- Error: " + e.Message);
        }
    }
开发者ID:Ronnie619,项目名称:TouchScreenKiosk,代码行数:29,代码来源:UIWindow.cs

示例9: Save

 public void Save(string path)
 {
     var serializer = new XmlSerializer(typeof(InputMap));
     using(var stream = new FileStream(path, FileMode.Create)){
         serializer.Serialize(stream, this);
     }
 }
开发者ID:jonbro,项目名称:hull_breach,代码行数:7,代码来源:InputMap.cs

示例10: CambiarNivel

    public void CambiarNivel()
    {
        string iniPath = "Config.xml";
        Config ini = null;
        try
        {
            StreamReader reader = new StreamReader(Path.Combine(Application.persistentDataPath, iniPath));
            XmlSerializer lectorXML = new XmlSerializer(typeof(Config));
            ini = (Config)lectorXML.Deserialize(reader);
            reader.Close();

        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
        if (ini != null)
        {
            try
            {
                XmlSerializer xmls = new XmlSerializer(typeof(Config));
                StreamWriter stream = new StreamWriter(Path.Combine(Application.persistentDataPath, iniPath));
                xmls.Serialize(stream, new Config(Input.text.ToString()));
                stream.Close();
            }
            catch (Exception e)
            {
                Debug.Log(e.ToString());
            }
        }
    }
开发者ID:alu0100693386,项目名称:TFG-Juegos-Serios-Unity,代码行数:31,代码来源:Controlador_Con.cs

示例11: WriteData

 public void WriteData(string filePath)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(Stats));
     FileStream stream = new FileStream(GameManager.STATS_DATA_PATH, FileMode.Create);
     serializer.Serialize(stream, this);
     stream.Close();
 }
开发者ID:MassonC,项目名称:MyRTS,代码行数:7,代码来源:Stats.cs

示例12: SaveToXML

	void SaveToXML(string filepath){		
		LinkableContentInfo info = ToInfo (this);
		XmlSerializer serializer = new XmlSerializer(typeof(LinkableContentInfo));
		FileStream stream = new FileStream( filepath, FileMode.Create);
		serializer.Serialize(stream, info);
		stream.Close();	
	}	
开发者ID:MedStarSiTEL,项目名称:UnityTrauma,代码行数:7,代码来源:ContentLinker.cs

示例13: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     Employee emp48090 = new Employee(48090, "naynish", 85000);
     XmlSerializer serial = new XmlSerializer(typeof(Employee));
     Stream stream = File.Create("");
     serial.Serialize(stream, emp48090);
 }
开发者ID:naynishchaughule,项目名称:ASP.NET,代码行数:7,代码来源:XmlSerial.aspx.cs

示例14: SerializeObject

 //string s = SerializationUtils.SerializeObject(g);
 //BeehiveGame a = (BeehiveGame)SerializationUtils.DeserializeObject(s, typeof(BeehiveGame));
 public static string SerializeObject(object o)
 {
     XmlSerializer xmlSerializer = new XmlSerializer(o.GetType());
     StringWriter textWriter = new StringWriter();
     xmlSerializer.Serialize(textWriter, o);
     return textWriter.ToString();
 }
开发者ID:rkonkul,项目名称:BeehiveCardGame,代码行数:9,代码来源:SerializationUtils.cs

示例15: SaveData

 public void SaveData()
 {
     using(FileStream stream = new FileStream(XmlAPI.PlayerDataPath(this.name),FileMode.Create)){
         XmlSerializer xmls = new XmlSerializer (typeof(PlayerSaveData));
         xmls.Serialize(stream,this);
     }
 }
开发者ID:newhandfun,项目名称:WOBAgithub,代码行数:7,代码来源:PlayerSaveData.cs


注:本文中的XmlSerializer.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。