Created
January 20, 2013 21:28
-
-
Save robertmclaws/4581894 to your computer and use it in GitHub Desktop.
Windows Phone WMAppManifest reader that doesn't waste cycles reading the file every time you need to access a value. Usage: var version = ApplicationInfo.Version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ApplicationInfo | |
{ | |
#region Private Members | |
const string AppManifestName = "WMAppManifest.xml"; | |
const string AppNodeName = "App"; | |
#endregion | |
#region Properties | |
public static string Title { get; private set; } | |
public static string Version { get; private set; } | |
public static string Author { get; private set; } | |
public static string Description { get; private set; } | |
#endregion | |
static ApplicationInfo() | |
{ | |
try | |
{ | |
var settings = new XmlReaderSettings { XmlResolver = new XmlXapResolver() }; | |
using (var rdr = XmlReader.Create(AppManifestName, settings)) | |
{ | |
rdr.ReadToDescendant(AppNodeName); | |
if (!rdr.IsStartElement()) | |
{ | |
throw new FormatException(AppManifestName + " is missing " + AppNodeName); | |
} | |
Title = rdr.GetAttribute("Title"); | |
Version = rdr.GetAttribute("Version"); | |
Author = rdr.GetAttribute("Author"); | |
Description = rdr.GetAttribute("Description"); | |
} | |
} | |
catch (Exception) | |
{ | |
; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment