本文整理匯總了C#中System.Xml.XmlDocument.Deserialize方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.Deserialize方法的具體用法?C# XmlDocument.Deserialize怎麽用?C# XmlDocument.Deserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.Deserialize方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TestXmlDocumentSeiralization
public void TestXmlDocumentSeiralization()
{
var objTree = new ObjectTree
{
Foo = "Foo1",
Bar = 1,
Nested = new List<object>()
};
objTree.Nested.AddRange(new[]
{
new ObjectTree{ Foo = "Foo2", Bar = 2},
new ObjectTree{ Foo = "Foo3", Bar = 3},
});
XmlDocument xmlDoc = objTree.ToXmlDocument();
string xml = xmlDoc.ToXml();
Assert.IsNotNull(xml);
XmlNode parentElem = xmlDoc.DocumentElement;
objTree.SerializeInto(parentElem);
xml = xmlDoc.ToXml();
Assert.IsNotNull(xml);
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
ObjectTree newObjectTree = xmlDoc.Deserialize<ObjectTree>();
Assert.IsNotNull(newObjectTree);
ObjectTree nested = newObjectTree.AnyXml.Deserialize<ObjectTree>();
Assert.AreEqual(1, nested.Bar);
Assert.AreEqual(objTree.Nested.Count, nested.Nested.Count);
}
示例2: Load
public static LoggerConfig Load(string xmlFilePath = null) {
if (xmlFilePath == null) {
xmlFilePath = c_xmlFilePath;
}
var doc = new XmlDocument();
doc.Load(xmlFilePath);
var nav = doc.CreateNavigator();
var ns = nav.GetNamespacesInScope(new XmlNamespaceScope());
return doc.Deserialize<LoggerConfig>();
}
示例3: Load
public void Load(string levelName)
{
if (levelName.StartsWith("JAFM_WORKAROUND_SAVE:")) {
string[] split = levelName.Split(new char[] {':'});
Save(split[1], (split.Length > 2) ? bool.Parse(split[2]) : false);
return;
}
if (levelName == "JAFM_WORKAROUND_CHANGELEVEL") {
ChangeLevel(GameLevelManagerHelper.ChangeLevel_);
return;
}
if (tmpLevel != null) {
ClearArtSatellites();
oldLevel = levelData;
levelData = tmpLevel;
tmpLevel = null;
levelData.OnDeserialization();
return;
}
levelName = FEZMod.ProcessLevelName(levelName);
string filePath_ = ("Resources\\levels\\"+(levelName.ToLower())).Replace("\\", Path.DirectorySeparatorChar.ToString()).Replace("/", Path.DirectorySeparatorChar.ToString())+".";
string filePathFMB = filePath_ + "fmb";
FileInfo fileFMB = new FileInfo(filePathFMB);
if (fileFMB.Exists) {
ModLogger.Log("FEZMod", "Loading level from FMB: "+levelName);
using (FileStream fs = new FileStream(fileFMB.FullName, FileMode.Open)) {
throw new FormatException("FEZMod can't load FMB files yet.");
}
return;
}
string filePathXML = filePath_+"xml";
FileInfo fileXML = new FileInfo(filePathXML);
if (!fileXML.Exists) {
if (MemoryContentManager.AssetExists("LEVELS/"+levelName)) {
orig_Load(levelName);
} else {
//Fallback: Spawn at the original VILLAGEVILLE_3D if the level wasn't found at all
ModLogger.Log("FEZMod", "Level not found: " + levelName + "; Falling back to the original VILLAGEVILLE_3D...");
orig_Load("VILLAGEVILLE_3D");
}
FEZMod.ProcessLevelData(levelData);
GameLevelManagerHelper.Level = levelData;
return;
}
ModLogger.Log("FEZMod", "Loading level from XML: "+levelName);
ClearArtSatellites();
oldLevel = levelData;
FileStream fis = new FileStream(fileXML.FullName, FileMode.Open);
XmlReader xmlReader = XmlReader.Create(fis);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(xmlReader);
xmlReader.Close();
fis.Close();
ContentManager cm = CMProvider.GetForLevel(levelName);
levelData = (Level) xmlDocument.Deserialize(null, cm, true);
levelData.Name = levelName;
LevelSaveData save = GameState.SaveData.ThisLevel;
if (save != null) {
save.FirstVisit = false;
}
FEZMod.ProcessLevelData(levelData);
GameLevelManagerHelper.Level = levelData;
}
示例4: ToXML2
public void ToXML2()
{
Assert.NotNull(TestItem.Serialize(new XMLSerializer(), FileLocation: @".\Testing\Test.xml"));
XmlDocument Document = new XmlDocument();
Document.LoadXml(new FileInfo(@".\Testing\Test.xml").Read());
TestClass Temp = Document.Deserialize<TestClass>(new XMLSerializer());
Assert.Equal(123, Temp.ID);
Assert.Equal("This is test content", Temp.Content);
}