Example #1
0
        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)
            {
                Assembly a = AppDomain.CurrentDomain.DoResourceResolve(name, this);
                if (a != null && a != this)
                {
                    return(a.GetManifestResourceStream(name));
                }
                else
                {
                    return(null);
                }
            }

            if (info.ReferencedAssembly != null)
            {
                return(info.ReferencedAssembly.GetManifestResourceStream(name));
            }
            if ((info.FileName != null) && (info.ResourceLocation == 0))
            {
                if (fromByteArray)
                {
                    throw new FileNotFoundException(info.FileName);
                }

                string location = Path.GetDirectoryName(Location);
                string filename = Path.Combine(location, info.FileName);
                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 UnmanagedMemoryStreamForModule((byte *)data, size, module);
                }
                return(stream);
            }
        }
Example #2
0
		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) {
				Assembly a = AppDomain.CurrentDomain.DoResourceResolve (name, this);
				if (a != null && a != this)
					return a.GetManifestResourceStream (name);
				else
					return null;
			}

			if (info.ReferencedAssembly != null)
				return info.ReferencedAssembly.GetManifestResourceStream (name);
			if ((info.FileName != null) && (info.ResourceLocation == 0)) {
				if (fromByteArray)
					throw new FileNotFoundException (info.FileName);

				string location = Path.GetDirectoryName (Location);
				string filename = Path.Combine (location, info.FileName);
				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 UnmanagedMemoryStreamForModule ((byte*) data, size, module);
				}
				return stream;
			}
		}