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