public string name;
public string filename;
public ResourceAttributes attrs;
+ public int offset;
}
public sealed class AssemblyBuilder : Assembly {
+ #region Sync with reflection.h
private IntPtr dynamic_assembly;
private MethodInfo entry_point;
private ModuleBuilder[] modules;
PEFileKinds pekind = PEFileKinds.Dll;
bool delay_sign;
uint access;
+ #endregion
internal Type corlib_object_type = typeof (System.Object);
internal Type corlib_value_type = typeof (System.ValueType);
internal Type corlib_enum_type = typeof (System.Enum);
namespace System.Reflection.Emit {
public class ModuleBuilder : Module {
+ #region Sync with reflection.h
private IntPtr dynamic_image;
private int num_types;
private TypeBuilder[] types;
private MethodBuilder[] global_methods;
private FieldBuilder[] global_fields;
bool is_main;
+ private MonoResource[] resources;
+ #endregion
private TypeBuilder global_type;
private Type global_type_created;
internal IMonoSymbolWriter symbol_writer;
private int[] table_indexes;
bool transient;
ModuleBuilderTokenGenerator token_gen;
+ ArrayList resource_writers = null;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void basic_init (ModuleBuilder ab);
return copy;
}
- [MonoTODO]
public IResourceWriter DefineResource (string name, string description, ResourceAttributes attribute)
{
if (name == null)
throw new InvalidOperationException ("The module is transient");
if (!assemblyb.IsSave)
throw new InvalidOperationException ("The assembly is transient");
- throw new NotImplementedException ();
+ ResourceWriter writer = new ResourceWriter (new MemoryStream ());
+ if (resource_writers == null)
+ resource_writers = new ArrayList ();
+ resource_writers.Add (writer);
+
+ // The data is filled out later
+ if (resources != null) {
+ MonoResource[] new_r = new MonoResource [resources.Length + 1];
+ System.Array.Copy(resources, new_r, resources.Length);
+ resources = new_r;
+ } else {
+ resources = new MonoResource [1];
+ }
+ int p = resources.Length - 1;
+ resources [p].name = name;
+ resources [p].attrs = attribute;
+
+ return writer;
}
public IResourceWriter DefineResource (string name, string description)
if (transient)
return;
+ if (resource_writers != null) {
+ for (int i = 0; i < resource_writers.Count; ++i) {
+ ResourceWriter writer = (ResourceWriter)resource_writers [i];
+ writer.Generate ();
+ MemoryStream stream = (MemoryStream)writer.Stream;
+ resources [i].data = new byte [stream.Length];
+ stream.Seek (0, SeekOrigin.Begin);
+ stream.Read (resources [i].data, 0, (int)stream.Length);
+ }
+ }
+
build_metadata (this);
if (symbol_writer != null) {