Esempio n. 1
0
        private void HandleReturnType(bool baseIsAbstractClass, TypeDefinition baseDefinition,
            MethodDefinition deepCopyMethod)
        {
            // Use the return type defined on the base method we're overriding (if applicable).
            if (!baseIsAbstractClass)
                return;

//            if (baseDefinition.TryGetMethod(this._deepCopyMethodName, out interCopy))
//            {
//                if (interCopy.IsVirtual)
//                    deepCopyMethod.Overrides.Add(interCopy);
//            }

            // Update the return type to match the one that we're supposed to override.
            MethodDefinition baseTypeDeepCopyMethod;
            if (baseDefinition.TryGetMethod(this._deepCopyMethodName, out baseTypeDeepCopyMethod))
                deepCopyMethod.ReturnType = baseTypeDeepCopyMethod.ReturnType;
        }
Esempio n. 2
0
        private void HandlePotentialAbstractOverride(bool baseIsAbstractClass, TypeDefinition baseDefinition,
            ref MethodAttributes methodAttributes)
        {
            if (!baseIsAbstractClass)
                return;

            // Get the deep copy method on the base type.
            MethodDefinition baseTypeDeepCopyMethod;
            if (!baseDefinition.TryGetMethod(this._deepCopyMethodName, out baseTypeDeepCopyMethod))
                return;

            // Is the deep copy method on the base type marked as 'override'?
            if (baseTypeDeepCopyMethod.IsVirtual)
                methodAttributes |= MethodAttributes.Virtual;
        }
Esempio n. 3
0
        private void SafeCallDeepCopy(
            Collection<VariableDefinition> variables,
            Collection<ExceptionHandler> exceptionHandlers,
            Collection<Instruction> instructions,
            TypeDefinition typeDefinition,
            Action<Collection<Instruction>> load,
            Action<Collection<Instruction>> store)
        {
            MethodDefinition deepCopy;
            if (!typeDefinition.TryGetMethod(this._deepCopyMethodName, out deepCopy))
                throw new Exception(
                    String.Format("Sub-type {0} does not implement DeepCopy.", typeDefinition.FullName));

            var var0 = variables.AddV(typeDefinition);

            // Load the object, and check to see if it's null.
            instructions.AddI(OpCodes.Nop);
            instructions.AddI(OpCodes.Ldarg_0);
            load(instructions);
            instructions.AddI(OpCodes.Stloc, var0);
            instructions.AddI(OpCodes.Ldloc_0);
            instructions.AddI(OpCodes.Ldloc, var0);

            var loadNull = Instruction.Create(OpCodes.Ldnull);
            instructions.AddI(OpCodes.Brfalse_S, loadNull);

            instructions.AddI(OpCodes.Ldloc, var0);
            instructions.AddI(OpCodes.Callvirt, deepCopy);
            var noOp = Instruction.Create(OpCodes.Nop);
            instructions.AddI(OpCodes.Br_S, noOp);

            instructions.Add(loadNull);

            instructions.Add(noOp);
            store(instructions);
        }