On Mon, Dec 6, 2010 at 6:40 PM, Greg Young <[email protected]> wrote:
> But you mentioned that the typereferences will still keep the module alive
> (thus all typereferences will be kept alive). Or am I misunderstanding you?

I guess. You'd need to have something like this:

static void CleanForCaching (TypeDefinition type)
{
        Detach (type.BaseType);

        foreach (var iface in type.Interfaces)
                Detach (iface);

        foreach (var field in type.Fields)
                Detach (field.FieldType);

        foreach (var method in type.Methods) {
                Detach (method.ReturnType);

                foreach (var parameter in method.Parameters) {
                        Detach (parameter.ParameterType);
                }
        }

        // ...
}

static void Detach (TypeReference type)
{
        if (type != null)
                type.Module = null;
}

But you have to be intrusive, for instance, you have to detach types
found in the IL body of methods, in custom attributes, and so forth
and so on.

All in all, it ends up being a bit tedious.

Caching an object model you control is probably easier.

Jb

-- 
--
mono-cecil

Reply via email to