public
Created

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.

  • Download Gist
ApplicationInfo.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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)
{
;
}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.