本文整理汇总了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, ""));
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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 ();
}
}
);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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 ();
}
示例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];
}
}
示例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();
}
示例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);
}
}