Exemplo n.º 1
0
        public void PreRename(ConfuserContext context, INameService service, IDnlibDef def)
        {
            var method = def as MethodDef;

            if (method == null || !method.IsVirtual)
            {
                return;
            }

            VTable vTbl = service.GetVTables()[method.DeclaringType];

            if (vTbl == null)             // This case occurs at late injected types, like delegates
            {
                return;
            }
            VTableSignature sig  = VTableSignature.FromMethod(method);
            VTableSlot      slot = vTbl.FindSlot(method);

            Debug.Assert(slot != null);

            // Can't rename virtual methods which implement an interface method or override a method declared in a base type,
            // when the interface or base type is declared in an assembly that is not currently being processed
            if (slot.Overrides.Any(slotOverride => !context.Modules.Any(module => module.Assembly.FullName == slotOverride.MethodDef.DeclaringType.DefinitionAssembly.FullName)))
            {
                service.SetCanRename(method, false);
            }
        }
Exemplo n.º 2
0
        public void Analyze(ConfuserContext context, INameService service, IDnlibDef def)
        {
            var method = def as MethodDef;

            if (method == null || !method.IsVirtual)
            {
                return;
            }

            VTable          vTbl = service.GetVTables()[method.DeclaringType];
            VTableSignature sig  = VTableSignature.FromMethod(method);
            VTableSlot      slot = vTbl.FindSlot(method);

            Debug.Assert(slot != null);

            if (!method.IsAbstract)
            {
                foreach (VTableSlot baseSlot in slot.Overrides)
                {
                    // Better on safe side, add references to both methods.
                    service.AddReference(method, new OverrideDirectiveReference(slot, baseSlot));
                    service.AddReference(baseSlot.MethodDef, new OverrideDirectiveReference(slot, baseSlot));
                }
            }
        }