[Mono-list] [patch] System.Reflection.Assemly.GetModules &
GetReferencedAssemblies.
Tomi Pakarinen
tomi.pakarinen@welho.com
01 Sep 2002 19:33:57 +0300
--=-I9E3eDjOrHw2QZuZ94X0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Tue, 2002-08-27 at 14:57, Paolo Molaro wrote:
> On 08/26/02 Tomi Pakarinen wrote:
> > I've implemented two methods:
> > System.Reflection.Assembly.GetModules()
> > System.Reflection.Assembly.GetReferencedAssemblies()
> >
> > GetModules implementation is not complete, because i couldn't find, how
> > to make a difference between resource modules and other kind of modules.
> > System.Reflection.Module.IsResource is unimplemented.
>
> Uhm, yes, the documentation is not clear on that point.
> You can safely leave that bit unimplemented for now.
>
Ok.
> > I've attached patches and a simple test program. I'm bit suspicious of
> > my mono_assemblyname_get_object & mono_module_get_object
> > implementations. I'm not sure, how those are supposed to be implemented.
>
> mono_module_get_object looks fine.
> As for GetReferencedAssemblies() I'd make a different icall that returns
> a Assembly[] and GetReferencedAssemblies() will create an AssemblyName
> array and fill it from the Assembly array (using Assembly.GetName).
> That way you don't need a mono_assemblyname_get_object().
I changed that. Here are new patches.
Tomi.
--=-I9E3eDjOrHw2QZuZ94X0
Content-Disposition: attachment; filename=GetAssemblies-mcs.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=GetAssemblies-mcs.patch; charset=ISO-8859-1
Index: class/corlib/System.Reflection/Assembly.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mcs/class/corlib/System.Reflection/Assembly.cs,v
retrieving revision 1.29
diff -u -r1.29 Assembly.cs
--- class/corlib/System.Reflection/Assembly.cs 21 Aug 2002 11:04:50 -0000 1=
.29
+++ class/corlib/System.Reflection/Assembly.cs 1 Sep 2002 16:07:48 -0000
@@ -282,9 +282,12 @@
throw new NotImplementedException ();
}
=20
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern Module[] GetModules (bool include_resources);
+
public Module[] GetModules ()
{
- throw new NotImplementedException ();
+ return GetModules (true);
}
=20
public Module GetModule (String name)
@@ -301,9 +304,16 @@
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static Assembly GetCallingAssembly ();
=20
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ private extern Assembly[] GetReferencedAssembliesInternal ();
+
public AssemblyName[] GetReferencedAssemblies ()
{
- throw new NotImplementedException ();
+ Assembly[] assemblies =3D GetReferencedAssembliesInternal();
+ AssemblyName[] names =3D new AssemblyName[assemblies.Length];
+ for ( int i=3D0; i<assemblies.Length; ++i )
+ names[i] =3D assemblies[i].GetName();
+ return names;
}
=20
public virtual ManifestResourceInfo GetManifestResourceInfo (String reso=
urceName)
--=-I9E3eDjOrHw2QZuZ94X0
Content-Disposition: attachment; filename=GetAssemblies-mono.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=GetAssemblies-mono.patch; charset=ISO-8859-1
Index: mono/metadata/icall.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/icall.c,v
retrieving revision 1.201
diff -u -r1.201 icall.c
--- mono/metadata/icall.c 29 Aug 2002 11:38:36 -0000 1.201
+++ mono/metadata/icall.c 1 Sep 2002 16:15:14 -0000
@@ -2047,6 +2047,33 @@
}
=20
=20
+static MonoArray*
+ves_icall_System_Reflection_Assembly_GetReferencedAssembliesInternal (Mono=
ReflectionAssembly *assembly)
+{
+ MonoDomain *domain =3D mono_domain_get();
+ MonoArray *res;
+ MonoClass *klass;
+ int i, count =3D 0;
+ MonoAssembly **refs =3D assembly->assembly->image->references;
+
+ if (refs)=20
+ {
+ while (refs[count])
+ ++count;
+ }
+
+ klass =3D mono_class_from_name ( mono_defaults.corlib, "System.Reflection=
", "Assembly");
+
+ res =3D mono_array_new (domain, klass, count);
+
+ for ( i =3D 0; i < count; ++i )
+ mono_array_set (res, gpointer, i, mono_assembly_get_object (domain, refs=
[i]));
+
+ return res;
+}
+
+
+
static MonoReflectionAssembly*
ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
{
@@ -2058,6 +2085,35 @@
return mono_assembly_get_object (mono_domain_get (), dest->klass->image->=
assembly);
}
=20
+static MonoArray*
+ves_icall_System_Reflection_Assembly_GetModules (MonoReflectionAssembly* a=
ssembly, MonoBoolean include_resource_modules )
+{
+ MonoDomain *domain =3D mono_domain_get();
+ MonoArray *res;
+ MonoClass *klass;
+ int i, count =3D 0;
+ MonoImage **modules =3D assembly->assembly->modules;
+
+ if (modules)=20
+ {
+ while (modules[count])
+ ++count;
+ }
+
+ g_assert( assembly->assembly->image !=3D NULL );
+ ++count;
+
+ klass =3D mono_class_from_name ( mono_defaults.corlib, "System.Reflection=
", "Module");
+ res =3D mono_array_new (domain, klass, count);
+
+ mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembl=
y->assembly->image));
+ for ( i =3D 1; i < count; ++i )=20
+ mono_array_set (res, gpointer, i, mono_module_get_object (domain, module=
s[i]));
+
+ return res;
+}
+
+
static MonoString *
ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
{
@@ -2889,8 +2945,10 @@
"System.Reflection.Assembly::FillName", ves_icall_System_Reflection_Assem=
bly_FillName,
"System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_=
Assembly_get_code_base,
"System.Reflection.Assembly::GetExecutingAssembly", ves_icall_System_Refl=
ection_Assembly_GetExecutingAssembly,
+ "System.Reflection.Assembly::GetReferencedAssembliesInternal", ves_icall_=
System_Reflection_Assembly_GetReferencedAssembliesInternal,
"System.Reflection.Assembly::GetEntryAssembly", ves_icall_System_Reflecti=
on_Assembly_GetEntryAssembly,
"System.Reflection.Assembly::GetCallingAssembly", ves_icall_System_Reflec=
tion_Assembly_GetCallingAssembly,
+ "System.Reflection.Assembly::GetModules", ves_icall_System_Reflection_Ass=
embly_GetModules,
"System.Reflection.Assembly::get_EntryPoint", ves_icall_System_Reflection=
_Assembly_get_EntryPoint,
"System.Reflection.Assembly::GetManifestResourceNames", ves_icall_System_=
Reflection_Assembly_GetManifestResourceNames,
"System.Reflection.Assembly::GetManifestResourceInternal", ves_icall_Syst=
em_Reflection_Assembly_GetManifestResourceInternal,
Index: mono/metadata/reflection.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/reflection.c,v
retrieving revision 1.107
diff -u -r1.107 reflection.c
--- mono/metadata/reflection.c 27 Aug 2002 14:39:19 -0000 1.107
+++ mono/metadata/reflection.c 1 Sep 2002 16:15:16 -0000
@@ -2692,6 +2692,31 @@
return res;
}
=20
+
+MonoReflectionModule* =20
+mono_module_get_object (MonoDomain *domain, MonoImage *image)
+{
+ static MonoClass *System_Reflection_Module;
+ MonoReflectionModule *res;
+=09
+ CHECK_OBJECT (MonoReflectionModule *, image, NULL);
+ if (!System_Reflection_Module)
+ System_Reflection_Module =3D mono_class_from_name (
+ mono_defaults.corlib, "System.Reflection", "Module");
+ res =3D (MonoReflectionModule *)mono_object_new (domain, System_Reflectio=
n_Module);
+
+ res->image =3D image;
+ res->assembly =3D (MonoReflectionAssembly *) mono_assembly_get_object(dom=
ain, image->assembly);
+
+ res->fqname =3D mono_string_new (domain, image->name);
+ res->name =3D mono_string_new (domain, image->name);
+ res->scopename =3D mono_string_new (domain, image->module_name);
+
+ CACHE_OBJECT (image, res, NULL);
+ return res;
+}
+
+
static gboolean
mymono_metadata_type_equal (MonoType *t1, MonoType *t2)
{
Index: mono/metadata/reflection.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/reflection.h,v
retrieving revision 1.55
diff -u -r1.55 reflection.h
--- mono/metadata/reflection.h 27 Aug 2002 14:42:07 -0000 1.55
+++ mono/metadata/reflection.h 1 Sep 2002 16:15:16 -0000
@@ -323,7 +323,7 @@
typedef struct {
MonoObject obj;
MonoImage *image;
- MonoObject *assembly;
+ MonoReflectionAssembly *assembly;
MonoString *fqname;
MonoString *name;
MonoString *scopename;
@@ -365,6 +365,16 @@
MonoString *codebase;
gint32 major, minor, build, revision;
/* FIXME: add missing stuff */
+/* CultureInfo cultureinfo;
+ AssemblyNameFlags flags;
+ AssemblyHashAlgorithm hashalg;
+ StrongNameKeyPair keypair;
+ AssemblyVersionCompatibility versioncompat;*/
+ MonoObject *cultureInfo;
+ MonoObject *flags;
+ MonoObject *hashalg;
+ MonoObject *keypair;
+ MonoObject *versioncompat;
} MonoReflectionAssemblyName;
=20
typedef struct {
@@ -417,6 +427,7 @@
guint32 mono_image_create_token (MonoDynamicAssembly *assembly, Mon=
oObject *obj);
=20
MonoReflectionAssembly* mono_assembly_get_object (MonoDomain *domain, Mono=
Assembly *assembly);
+MonoReflectionModule* mono_module_get_object (MonoDomain *domain, Mono=
Image *image);
MonoReflectionType* mono_type_get_object (MonoDomain *domain, Mono=
Type *type);
MonoReflectionMethod* mono_method_get_object (MonoDomain *domain, Mono=
Method *method, MonoClass *refclass);
MonoReflectionField* mono_field_get_object (MonoDomain *domain, Mono=
Class *klass, MonoClassField *field);
--=-I9E3eDjOrHw2QZuZ94X0--