コード例 #1
0
        public static string GetResourceText(Assembly assembly, ConDepResource resource)
        {
            try
            {
                using (var stream = assembly.GetManifestResourceStream(resource.Namespace + "." + resource.Resource))
                {
                    if (stream == null)
                    {
                        throw new ConDepResourceNotFoundException(string.Format("Unable to find resource [{0}]", resource.Resource));
                    }

                    using (var reader = new StreamReader(stream))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ConDepResourceNotFoundException(string.Format("Resource [{0}]", resource.Resource), ex);
            }
        }
コード例 #2
0
        public static byte[] GetResourceBytes(Assembly assembly, ConDepResource resource)
        {
            try
            {
                using (var stream = assembly.GetManifestResourceStream(resource.Namespace + "." + resource.Resource))
                {
                    if (stream == null)
                    {
                        throw new ConDepResourceNotFoundException(string.Format("Unable to find resource [{0}]", resource.Resource));
                    }

                    using (var memoryStream = new MemoryStream())
                    {
                        stream.CopyTo(memoryStream);
                        return(memoryStream.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ConDepResourceNotFoundException(string.Format("Resource [{0}]", resource.Resource), ex);
            }
        }