示例#1
0
        public CilBodyOptions CopyTo(CilBodyOptions options)
        {
            var ops = new Dictionary <object, object>();

            foreach (var vm in LocalsListVM)
            {
                ops.Add(vm, vm.CreateLocalOptions().Create());
            }
            foreach (var vm in InstructionsListVM)
            {
                ops.Add(vm, new Instruction());
            }

            options.KeepOldMaxStack = KeepOldMaxStack;
            options.InitLocals      = InitLocals;
            options.MaxStack        = MaxStack.Value;
            options.LocalVarSigTok  = LocalVarSigTok.Value;
            options.HeaderSize      = HeaderSize.Value;
            options.Locals.Clear();
            options.Locals.AddRange(LocalsListVM.Select(a => (Local)ops[a]));
            options.Instructions.Clear();
            options.Instructions.AddRange(InstructionsListVM.Select(a => a.CreateInstructionOptions().CopyTo(ops, (Instruction)ops[a])));
            options.ExceptionHandlers.Clear();
            options.ExceptionHandlers.AddRange(ExceptionHandlersListVM.Select(a => a.CreateExceptionHandlerOptions().Create(ops)));
            return(options);
        }
示例#2
0
        void ExceptionHandlersUpdateIndexes(int i)
        {
            var old = DisableHasError();

            try {
                ExceptionHandlersListVM.DefaultUpdateIndexes(i);
            }
            finally {
                RestoreHasError(old);
            }
        }
示例#3
0
        public void InitializeFrom(CilBodyOptions options)
        {
            try {
                LocalsListVM.DisableAutoUpdateProps            = true;
                InstructionsListVM.DisableAutoUpdateProps      = true;
                ExceptionHandlersListVM.DisableAutoUpdateProps = true;
                HasError_disabled = true;

                var ops = new Dictionary <object, object>();
                foreach (var local in options.Locals)
                {
                    ops.Add(local, new LocalVM(TypeSigCreatorOptions, new LocalOptions(local)));
                }
                foreach (var instr in options.Instructions)
                {
                    ops.Add(instr, new InstructionVM());
                }
                foreach (var instr in options.Instructions)
                {
                    ((InstructionVM)ops[instr]).Initialize(new InstructionOptions(ops, instr));
                }

                KeepOldMaxStack        = options.KeepOldMaxStack;
                InitLocals             = options.InitLocals;
                MaxStack.Value         = options.MaxStack;
                LocalVarSigTok.Value   = options.LocalVarSigTok;
                HeaderSize.Value       = options.HeaderSize;
                HeaderRVA.Value        = (uint)options.HeaderRVA;
                HeaderFileOffset.Value = unchecked ((ulong)(long)options.HeaderFileOffset);
                RVA.Value        = (uint)options.RVA;
                FileOffset.Value = unchecked ((ulong)(long)options.FileOffset);
                LocalsListVM.Clear();
                LocalsListVM.AddRange(options.Locals.Select(a => (LocalVM)ops[a]));
                InstructionsListVM.Clear();
                InstructionsListVM.AddRange(options.Instructions.Select(a => (InstructionVM)ops[a]));
                ExceptionHandlersListVM.Clear();
                ExceptionHandlersListVM.AddRange(options.ExceptionHandlers.Select(a => new ExceptionHandlerVM(TypeSigCreatorOptions, new ExceptionHandlerOptions(ops, a))));
            }
            finally {
                HasError_disabled = false;
                LocalsListVM.DisableAutoUpdateProps            = false;
                InstructionsListVM.DisableAutoUpdateProps      = false;
                ExceptionHandlersListVM.DisableAutoUpdateProps = false;
            }
            LocalsUpdateIndexes(0);
            InstructionsUpdateIndexes(0);
            ExceptionHandlersUpdateIndexes(0);
            HasErrorUpdated();
        }