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


C# XmlSerializer.Deserialize方法代码示例

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


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

示例1: NullDeserialize

 public void NullDeserialize()
 {
     var Temp = new XmlSerializer();
     Assert.Equal(null, Temp.Deserialize(typeof(TestObject), null));
     Assert.Equal(null, Temp.Deserialize(typeof(TestObject), ""));
     Assert.Equal(null, Temp.Deserialize(null, ""));
 }
开发者ID:modulexcite,项目名称:Craig-s-Utility-Library,代码行数:7,代码来源:XmlSerializer.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: Load

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

        if (File.Exists(Path.Combine(Application.persistentDataPath, "levelsEasy.xml")))
        {
            using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsEasy.xml"), FileMode.Open)) easyLevels = (List<Level>)serializer.Deserialize(stream);
            using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsMedium.xml"), FileMode.Open)) mediumLevels = (List<Level>)serializer.Deserialize(stream);
            using (FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, "levelsHard.xml"), FileMode.Open)) hardLevels = (List<Level>)serializer.Deserialize(stream);
        }
        else createNewXML();
    }
开发者ID:mengtest,项目名称:Sudoku,代码行数:12,代码来源:LevelManager.cs

示例4: createNewXML

    private static void createNewXML()
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List<Level>));

        TextAsset XmlLevelsEasy = Resources.Load("levelsEasyXMLprefab") as TextAsset;
        TextAsset XmlLevelsMedium = Resources.Load("levelsMediumXMLprefab") as TextAsset;
        TextAsset XmlLevelsHard = Resources.Load("levelsHardXMLprefab") as TextAsset;

        using (StringReader reader = new StringReader(XmlLevelsEasy.text)) easyLevels = (List<Level>)serializer.Deserialize(reader);
        using (StringReader reader = new StringReader(XmlLevelsMedium.text)) mediumLevels = (List<Level>)serializer.Deserialize(reader);
        using (StringReader reader = new StringReader(XmlLevelsHard.text)) hardLevels = (List<Level>)serializer.Deserialize(reader);

        Save();
    }
开发者ID:mengtest,项目名称:Sudoku,代码行数:14,代码来源:LevelManager.cs

示例5: ImportProteinSettings

    public void ImportProteinSettings()
    {
        try
        {
            ////read
            serializer = new XmlSerializer(typeof(CutParametersContainer));
            stream = new FileStream(path, FileMode.Open);
            CutParametersContainer importParams = serializer.Deserialize(stream) as CutParametersContainer;
            stream.Close();

            for (int i = 0; i < importParams.CutObjectProps.Count && i < SceneManager.Get.CutObjects.Count; i++)
            {
                SceneManager.Get.CutObjects[i].IngredientCutParameters = importParams.CutObjectProps[i].ProteinTypeParameters;
                SceneManager.Get.CutObjects[i].Inverse = importParams.CutObjectProps[i].Inverse;
                SceneManager.Get.CutObjects[i].CutType = (CutType) importParams.CutObjectProps[i].CutType;

                //restore transform info
                SceneManager.Get.CutObjects[i].transform.rotation = importParams.CutObjectProps[i].rotation;
                SceneManager.Get.CutObjects[i].transform.position = importParams.CutObjectProps[i].position;
                SceneManager.Get.CutObjects[i].transform.localScale = importParams.CutObjectProps[i].scale;
            }
        }
        catch(Exception e)
        {
            Debug.Log("import failed: " + e.ToString());
            return;
        }

        Debug.Log("imported cutobject settings from " + path);
    }
开发者ID:jaronimoe,项目名称:cellVIEW_animated,代码行数:30,代码来源:tmp_util.cs

示例6: DeserializeObject

	public object DeserializeObject(string pXmlizedString , System.Type ty)
	{
		XmlSerializer xs  = new XmlSerializer(ty);
		MemoryStream memoryStream  = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
		XmlTextWriter xmlTextWriter   = new XmlTextWriter(memoryStream, Encoding.UTF8);
		return xs.Deserialize(memoryStream);
	}
开发者ID:CCCarrion,项目名称:Star-Counter,代码行数:7,代码来源:XmlSaver.cs

示例7: SearchTweets

    public static IObservable<TweetList> SearchTweets(string query)
    {
        string url = GetQueryURL (query);

        return ObservableWWW.Get (url)
            .Select (
                xml => {
                    try
                    {
                        Debug.Log (string.Format ("Retrieved Tweets for query {0} successfully", query));
                        XmlSerializer ser = new XmlSerializer(typeof(TweetList));

                        // Declare an object variable of the type to be deserialized.
                        using (Stream reader = GenerateStreamFromString (xml))
                        {
                            // Call the Deserialize method to restore the object's state.
                            return (ser.Deserialize (reader) as TweetList);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError (string.Format ("Failed to deserialize Tweets from query: {0}, ex: {1}", query, e));
                        return new TweetList ();
                    }
                }
            );
    }
开发者ID:XavierS1984,项目名称:hackjunction-multitaction-demo,代码行数:27,代码来源:QueryfeedAPI.cs

示例8: OnHandleResponse

    public override void OnHandleResponse(OperationResponse response)
    {

        NetworkManager view = _controller.ControlledView as NetworkManager;
        view.LogDebug("GOT A RESPONSE for KNOWN STARS");
        if (response.ReturnCode == 0)
        {
            view.LogDebug(response.Parameters[(byte)ClientParameterCode.KnownStars].ToString());

            // Deserialize
            var xmlData = response.Parameters[(byte)ClientParameterCode.KnownStars].ToString();
            XmlSerializer deserializer = new XmlSerializer(typeof(XmlStarPlayerList));
            TextReader reader = new StringReader(xmlData);
            object obj = deserializer.Deserialize(reader);
            XmlStarPlayerList starCollection = (XmlStarPlayerList)obj;
            reader.Close();

            List<KnownStar> stars = new List<KnownStar>();
            foreach (SanStarPlayer s in starCollection.StarPlayers)
                stars.Add(new KnownStar(s));

            // Update local data
            PlayerData.instance.UpdateKnownStars(stars);
        }
        else
        {
            view.LogDebug("RESPONSE: " + response.DebugMessage);
            DisplayManager.Instance.DisplayMessage(response.DebugMessage);
        }
    }
开发者ID:seanbraley,项目名称:PocketCosmos,代码行数:30,代码来源:KnownStarsResponseHandler.cs

示例9: LoadData

 public static XMLContainer LoadData(string path)
 {
     var serializer = new XmlSerializer(typeof(XMLContainer));
     using(var stream = new FileStream(path, FileMode.Open)) {
         return serializer.Deserialize(stream) as XMLContainer;
     }
 }
开发者ID:moriz1,项目名称:CordycepSim,代码行数:7,代码来源:XMLHandler.cs

示例10: generateLevel

    //Funcion que con el nombre del nivel (el mismo que el del xml) crea los gameobjects del nivel
    public GameObject generateLevel(string nameLevel)
    {
        //Extraemos el XML y lo deserializamos
        TextAsset xmlTextAsset = (TextAsset)Resources.Load("LevelsXML/"+nameLevel, typeof(TextAsset));
        StringReader stream = new StringReader(xmlTextAsset.text);
        XmlSerializer s = new XmlSerializer(typeof(structureXML));
        m_structureXML = s.Deserialize(stream) as structureXML;

        //Creamos un gameObject vacio que representará el nivel
        GameObject goLevel = new GameObject(nameLevel);
        goLevel.transform.position = Vector3.zero;
        goLevel.transform.parent = Managers.GetInstance.SceneMgr.rootScene.transform;

        Managers.GetInstance.TimeMgr.seconds = m_structureXML.time.seconds;
        Managers.GetInstance.SceneMgr.spawnPointPlayer = new Vector3(m_structureXML.spawnPoint.x, m_structureXML.spawnPoint.y, 0);

        //Creamos cada uno de los items definidos en el XML en la posicion alli indicada, con el scale alli indicado.
        foreach (structureXML.Item go in m_structureXML.prefabs.items)
        {
            GameObject newGO = Managers.GetInstance.SpawnerMgr.createGameObject(Resources.Load("Prefabs/GamePrefabs/" + go.prefab) as GameObject, new Vector3(go.x, go.y, 0), Quaternion.identity);
            newGO.transform.localScale = new Vector3(go.scaleX, go.scaleY, 1);
            //Finalmente como padre ponemos al gameObject que representa el nivel
            newGO.transform.parent = goLevel.transform;
        }

        return goLevel;
    }
开发者ID:cesarpazguzman,项目名称:platform2DUnity,代码行数:28,代码来源:createLevelFromXML.cs

示例11: SetPlayer

 public void SetPlayer(string data)
 {
     var serializer = new XmlSerializer(typeof(Character));
     var stream = new MemoryStream(Encoding.ASCII.GetBytes(data));
     playerData = serializer.Deserialize(stream) as Character;
     stream.Close();
 }
开发者ID:Hoon-Park,项目名称:MMOArenaUnity,代码行数:7,代码来源:GameController.cs

示例12: 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

示例13: RecordedRawOutput

    public RecordedRawOutput(string filename)
    {
        r = new System.Random();
        startTime = DateTime.Now;
        lastTime = DateTime.Now;

        if(File.Exists(filename)){
          // grab the XML serialized data from a file
          FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
          XmlSerializer xs = new XmlSerializer(typeof(DataContainer));

          // then try to deserialize it
          try {
        container = (DataContainer)xs.Deserialize(stream);
          }
          catch(FileNotFoundException e){
        container.dataPairs = new RawDataPair[0];
          }
          catch(Exception e){
        Debug.Log("General exception: " + e);
          }

          /*
          stream.Close();
          */
        }
        else {
          container.dataPairs = new RawDataPair[0];
        }
    }
开发者ID:blyk,项目名称:BlackCode-Processing,代码行数:30,代码来源:RecordedRawOutput.cs

示例14: CreateItem

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

        System.Type[] itemTypes = { typeof(Equipment), typeof(Weapon), typeof(Consumable) };

        XmlSerializer serializer = new XmlSerializer(typeof(ItemContainer), itemTypes);

        FileStream fs = new FileStream(Path.Combine(Application.streamingAssetsPath, "Items.xml"), FileMode.Open);

        itemContainer = (ItemContainer)serializer.Deserialize(fs);

        fs.Close();

        switch (category)
        {
            case Category.Equipment:
                itemContainer.Equipments.Add(new Equipment(currentId, itemName, description, itemType, quality, spritePath, malePath, femalePath, maxStackSize, strenght, dexterity, stamina, magic));
                break;
            case Category.Weapon:
                itemContainer.Weapons.Add(new Weapon(currentId, itemName, description, itemType, quality, spritePath, malePath, femalePath, maxStackSize, strenght, dexterity, stamina, magic, attack, defence));
                break;
            case Category.Consumable:
                itemContainer.Consumables.Add(new Consumable(currentId, itemName, description, itemType, quality, spritePath, maxStackSize, health, mana));
                break;
            default:
                break;
        }

        fs = new FileStream(Path.Combine(Application.streamingAssetsPath, "Items.xml"), FileMode.Create);
        serializer.Serialize(fs, itemContainer);
        fs.Close();
    }
开发者ID:thyjukki,项目名称:Rebelion,代码行数:34,代码来源:ItemCreator.cs

示例15: ComprobarDatos

    public void ComprobarDatos(int scena)
    {
        string path = "Personalizacion.xml";
        Personaje pj = null;
        try
        {
            StreamReader reader = new StreamReader(Path.Combine(Application.persistentDataPath, path));
            XmlSerializer lectorXML = new XmlSerializer(typeof (Personaje));
            pj = (Personaje) lectorXML.Deserialize(reader);
            reader.Close();

        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
        if (pj == null)
        {
            CambiarEscena(1);
        }
        else
        {
            Debug.Log(pj.Name);
            CambiarEscena(2);
        }
    }
开发者ID:alu0100693386,项目名称:TFG-Juegos-Serios-Unity,代码行数:26,代码来源:Controlador_UI.cs


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