Plugin.EmbeddedResource/ResourceLoader.cs
/// <summary>
/// Attempts to find and return the given resource from within the specified assembly.
/// </summary>
/// <returns>The embedded resource stream.</returns>
/// <param name="assembly"><see cref="Assembly"/> containing embedded resources.</param>
/// <param name="resource">Full name of embedded resource in <see cref="Assembly"/>.</param>
Attempts to find and return the given resource from within the specified assembly.
Attempts to find and return the given resource from within the specified assembly .
public static Stream GetEmbeddedResourceStream(Assembly assembly, string resource)
		{
			var resourceNames = assembly.GetManifestResourceNames();
			var resourcePaths = resourceNames
				.Where(x => x.EndsWith(resource, StringComparison.CurrentCultureIgnoreCase))
				.ToArray();
			if (!resourcePaths.Any())
			{
				throw new Exception(string.Format("Resource ending with {0} not found.", resource));
			}
			if (resourcePaths.Count() > 1)
			{
				throw new Exception(string.Format("Multiple resources ending with {0} found: {1}{2}", resource, Environment.NewLine, string.Join(Environment.NewLine, resourcePaths)));
			}
			return assembly.GetManifestResourceStream(resourcePaths.Single());
		}
public static Stream GetEmbeddedResourceStream ( Assembly assembly , string resource ) { var resourceNames = assembly . GetManifestResourceNames ( ) ; var resourcePaths = resourceNames . Where ( x => x . EndsWith ( resource , StringComparison . CurrentCultureIgnoreCase ) ) . ToArray ( ) ; if ( ! resourcePaths . Any ( ) ) { throw new Exception ( string . Format ( " " , resource ) ) ; } if ( resourcePaths . Count ( ) > 1 ) { throw new Exception ( string . Format ( " " , resource , Environment . NewLine , string . Join ( Environment . NewLine , resourcePaths ) ) ) ; } return assembly . GetManifestResourceStream ( resourcePaths . Single ( ) ) ; }
Attempts to find and return the given resource from within the specified assembly.
Attempts to find and return the given resource from within the specified assembly .
The embedded resource stream.
The embedded resource stream .
assembly
Assembly
containing embedded resources.
containing embedded resources .
resource
string
Full name of embedded resource in .
Full name of embedded resource in .