Skip to content

Instantly share code, notes, and snippets.

@robertmclaws
Created January 20, 2013 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertmclaws/4581894 to your computer and use it in GitHub Desktop.
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.
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