private void ParseObjectInitializerScope(ObjectInitializerScope objectInitializerScope, MethodDefinition methodDefinition, List <Triple> triples) { foreach (var memberScope in objectInitializerScope.MemberScopes) { ParseMemberScope(memberScope, methodDefinition, triples); } }
public static ObjectInitializerScope BuildObjectInitializer(Instruction contructorInstruction, MethodDefinition parentMethod) { var objectInitializerScope = new ObjectInitializerScope(); objectInitializerScope.ParentMethod = parentMethod; objectInitializerScope.ConstructorInstruction = contructorInstruction; objectInitializerScope.ConstructorInstructionKey = InstructionKeyService.GetInstructionKey(contructorInstruction, parentMethod); objectInitializerScope.ConstructorOwnerKey = Guid.NewGuid().ToString(); var currentMemberScope = new MemberScope(); currentMemberScope.Parent = objectInitializerScope; objectInitializerScope.MemberScopes.Add(currentMemberScope); try { var instructionCursor = contructorInstruction.Next; while (instructionCursor != null && instructionCursor.Next != null) { if (instructionCursor.OpCode.Code == Mono.Cecil.Cil.Code.Nop && instructionCursor.Next.OpCode.Code == Mono.Cecil.Cil.Code.Dup) { currentMemberScope.Instructions.Add(instructionCursor); currentMemberScope = new MemberScope(); currentMemberScope.Parent = objectInitializerScope; objectInitializerScope.MemberScopes.Add(currentMemberScope); } else if (instructionCursor.OpCode.Code == Mono.Cecil.Cil.Code.Nop && instructionCursor.Next.OpCode.Code != Mono.Cecil.Cil.Code.Dup) { currentMemberScope.Instructions.Add(instructionCursor); break; } else if (IsNewObjectInitializerScope(instructionCursor)) { currentMemberScope.Instructions.Add(instructionCursor); currentMemberScope.NestedScope = BuildObjectInitializer(instructionCursor, parentMethod); var nestedScopeEndOffset = currentMemberScope.NestedScope.GetEndOffset(); instructionCursor = JumpToInstructionAfterOffset(parentMethod, nestedScopeEndOffset); if (instructionCursor == null) { break; } currentMemberScope.Instructions.Add(instructionCursor); } else { currentMemberScope.Instructions.Add(instructionCursor); } instructionCursor = instructionCursor.Next; } } catch (Exception ex) { } foreach (var memberScope in objectInitializerScope.MemberScopes) { ReorderInstructions(memberScope.Instructions); } return(objectInitializerScope); }