public virtual Stream GetManifestResourceStream (String name)
{
if (name == null)
throw new ArgumentNullException ("name");
if (name.Length == 0)
throw new ArgumentException ("String cannot have zero length.",
"name");
ManifestResourceInfo info = GetManifestResourceInfo (name);
if (info == null)
return null;
if (info.ReferencedAssembly != null)
return info.ReferencedAssembly.GetManifestResourceStream (name);
if ((info.FileName != null) && (info.ResourceLocation == 0)) {
if (fromByteArray)
#if NET_2_0
throw new FileNotFoundException (info.FileName);
#else
return null;
#endif
string location = Path.GetDirectoryName (Location);
string filename = Path.Combine (location, info.FileName);
#if NET_2_1 && !MONOTOUCH
// we don't control the content of 'info.FileName' so we want to make sure we keep to ourselves
filename = Path.GetFullPath (filename);
if (!filename.StartsWith (location))
throw new SecurityException ("non-rooted access to manifest resource");
#endif
return new FileStream (filename, FileMode.Open, FileAccess.Read);
}
int size;
Module module;
IntPtr data = GetManifestResourceInternal (name, out size, out module);
if (data == (IntPtr) 0)
return null;
else {
UnmanagedMemoryStream stream;
unsafe {
stream = new UnmanagedMemoryStream ((byte*) data, size);
}
/*
* The returned pointer points inside metadata, so
* we have to increase the refcount of the module, and decrease
* it when the stream is finalized.
*/
stream.Closed += new EventHandler (new ResourceCloseHandler (module).OnClose);
return stream;
}
}