5
5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2010 Jb Evain
9
9
// Permission is hereby granted, free of charge, to any person obtaining
10
10
// a copy of this software and associated documentation files (the
26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
32
namespace Mono.Cecil {
31
34
public sealed class EmbeddedResource : Resource {
36
get { return m_data; }
37
set { m_data = value; }
40
public EmbeddedResource (string name, ManifestResourceAttributes flags) :
45
public EmbeddedResource (string name, ManifestResourceAttributes flags, byte [] data) :
51
public override void Accept (IReflectionStructureVisitor visitor)
53
visitor.VisitEmbeddedResource (this);
36
readonly MetadataReader reader;
42
public override ResourceType ResourceType {
43
get { return ResourceType.Embedded; }
46
public EmbeddedResource (string name, ManifestResourceAttributes attributes, byte [] data) :
47
base (name, attributes)
52
public EmbeddedResource (string name, ManifestResourceAttributes attributes, Stream stream) :
53
base (name, attributes)
58
internal EmbeddedResource (string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
59
: base (name, attributes)
65
public Stream GetResourceStream ()
71
return new MemoryStream (data);
74
return reader.GetManagedResourceStream (offset.Value);
76
throw new InvalidOperationException ();
79
public byte [] GetResourceData ()
82
return ReadStream (stream);
88
return reader.GetManagedResourceStream (offset.Value).ToArray ();
90
throw new InvalidOperationException ();
93
static byte [] ReadStream (Stream stream)
95
var length = (int) stream.Length;
96
var data = new byte [length];
99
while ((read = stream.Read (data, offset, length - offset)) > 0)