Beispiel #1
0
        private static Stream InternalTryGetResource(Assembly assembly, string defaultNamespace, IEnumerable <string> resourcePath, bool failOnMissingResource)
        {
            string text   = ResourcesManager.ComputeEmbeddedResourceName(defaultNamespace, resourcePath);
            Stream stream = assembly.GetManifestResourceStream(text);

            if (stream == null)
            {
                string name = assembly.GetName().Name;
                string arg  = string.Join("/", resourcePath);
                try
                {
                    StreamResourceInfo resourceStream = Application.GetResourceStream(new Uri(string.Format("/{0};component/{1}", name, arg), UriKind.Relative));
                    stream = ((resourceStream != null) ? resourceStream.Stream : null);
                }
                catch (IOException)
                {
                }
            }
            if (failOnMissingResource && stream == null)
            {
                throw new InvalidOperationException("Resource not found: " + text);
            }
            return(stream);
        }
Beispiel #2
0
 protected virtual Stream TryGetResourceWithFullPath(Assembly assembly, IEnumerable <string> resourcePath)
 {
     return(ResourcesManager.TryGetResourceWithFullPath(assembly, resourcePath));
 }
Beispiel #3
0
 public static Stream TryGetResourceWithFullPath(string assemblyName, IEnumerable <string> resourcePath)
 {
     return(ResourcesManager.InternalTryGetResource(assemblyName, resourcePath.First <string>(), resourcePath.Skip(1), false));
 }
Beispiel #4
0
 public static Stream TryGetResource(string assemblyName, IEnumerable <string> resourcePath)
 {
     return(ResourcesManager.InternalTryGetResource(assemblyName, assemblyName, resourcePath, false));
 }
Beispiel #5
0
 public static Stream GetResource(Assembly assembly, IEnumerable <string> resourcePath)
 {
     return(ResourcesManager.InternalTryGetResource(assembly, assembly.GetName().Name, resourcePath, true));
 }
Beispiel #6
0
 public static Stream GetResourceWithFullPath(Assembly assembly, IEnumerable <string> resourcePath)
 {
     return(ResourcesManager.InternalTryGetResource(assembly, resourcePath.First <string>(), resourcePath.Skip(1), true));
 }