System.Windows.Application.GetXapResource C# (CSharp) Method

GetXapResource() static private method

static private GetXapResource ( string resource ) : System.Windows.Resources.StreamResourceInfo
resource string
return System.Windows.Resources.StreamResourceInfo
		unsafe static StreamResourceInfo GetXapResource (string resource)
		{
			try {
				string canon = Helper.CanonicalizeResourceName (resource);
				string res_file = Path.GetFullPath (Path.Combine (Deployment.Current.XapDir, canon));
				// ensure the file path is rooted against the XAP directory and that it exists
				if (!res_file.StartsWith (Deployment.Current.XapDir) || !File.Exists (res_file))
					return null;

				byte[] data = null;
				// we don't want to run out of file handles (see bug #535709) so we cache the data in memory
				if (!local_xap_resources.TryGetValue (res_file, out data)) {
					data = File.ReadAllBytes (res_file);
					local_xap_resources.Add (res_file, data);
				}
				fixed (byte* ptr = &data [0]) {
					Stream ums = new UnmanagedMemoryStream (ptr, data.Length, data.Length, FileAccess.Read);
					return new StreamResourceInfo (ums, null);
				}
			}
			catch {
				return null;
			}
		}