Esempio n. 1
0
        public IEnumerable <FieldDef> cleanUp()
        {
            var removedFields = new List <FieldDef>();
            var moduleCctor   = DotNetUtils.getModuleTypeCctor(module);

            if (moduleCctor == null)
            {
                return(removedFields);
            }
            var moduleCctorBlocks = new Blocks(moduleCctor);

            var keep = findFieldsToKeep();

            foreach (var fieldInfo in fieldToInfo.getValues())
            {
                if (keep.ContainsKey(fieldInfo))
                {
                    continue;
                }
                if (removeInitCode(moduleCctorBlocks, fieldInfo))
                {
                    removedFields.Add(fieldInfo.field);
                    removedFields.Add(fieldInfo.arrayInitField);
                }
                fieldInfo.arrayInitField.InitialValue  = new byte[1];
                fieldInfo.arrayInitField.FieldSig.Type = module.CorLibTypes.Byte;
                fieldInfo.arrayInitField.RVA           = 0;
            }

            IList <Instruction>      allInstructions;
            IList <ExceptionHandler> allExceptionHandlers;

            moduleCctorBlocks.getCode(out allInstructions, out allExceptionHandlers);
            DotNetUtils.restoreBody(moduleCctorBlocks.Method, allInstructions, allExceptionHandlers);
            return(removedFields);
        }