예제 #1
0
        private void AddCustomLogicCall(TypeDefDeclaration enhancedType, InstructionWriter writer,
                                        MethodDefDeclaration customMethod)
        {
            var parameters = customMethod.Parameters;

            if (parameters.Count != 0)
            {
                Message.Write(enhancedType, SeverityType.Error, "EQU1", "The signature of a method annotated with ["
                              + nameof(AdditionalGetHashCodeMethodAttribute) +
                              "] must be 'int MethodName()'. It can't have parameters.");
                writer.EmitInstruction(OpCodeNumber.Ldc_I4_0);
                return;
            }

            if (!customMethod.ReturnParameter.ParameterType.IsIntrinsic(IntrinsicType.Int32))
            {
                Message.Write(enhancedType, SeverityType.Error, "EQU2", "The signature of a method annotated with ["
                              + nameof(AdditionalGetHashCodeMethodAttribute) +
                              "] must be 'int MethodName()'. Its return type must be 'int'.");
                writer.EmitInstruction(OpCodeNumber.Ldc_I4_0);
                return;
            }

            writer.EmitInstruction(OpCodeNumber.Ldarg_0);
            writer.EmitInstructionMethod(
                enhancedType.IsValueTypeSafe() == true ? OpCodeNumber.Call : OpCodeNumber.Callvirt,
                customMethod.GetCanonicalGenericInstance());
        }
        private void EmitEqualsObjectOfValueType(InstructionWriter writer,
                                                 IType genericTypeInstance, MethodDefDeclaration typedEqualsMethod, CreatedEmptyMethod methodBody)
        {
            // return this.Equals((Typed)other);
            writer.EmitInstruction(OpCodeNumber.Ldarg_0);
            writer.EmitInstruction(OpCodeNumber.Ldarg_1);
            writer.EmitInstructionType(OpCodeNumber.Unbox_Any, genericTypeInstance);
            writer.EmitInstructionMethod(OpCodeNumber.Call, typedEqualsMethod.GetCanonicalGenericInstance());

            writer.EmitInstructionLocalVariable(OpCodeNumber.Stloc, methodBody.ReturnVariable);
            writer.EmitBranchingInstruction(OpCodeNumber.Br, methodBody.ReturnSequence);
        }
        private void EmitEqualsObjectOfReferenceType(InstructionWriter writer, IType genericTypeInstance,
                                                     MethodDefDeclaration typedEqualsMethod, CreatedEmptyMethod methodBody)
        {
            // Go to typed check.
            writer.EmitInstruction(OpCodeNumber.Ldarg_0);
            writer.EmitInstruction(OpCodeNumber.Ldarg_1);
            writer.EmitInstructionType(OpCodeNumber.Castclass, genericTypeInstance);
            writer.EmitInstructionMethod(OpCodeNumber.Call, typedEqualsMethod.GetCanonicalGenericInstance());

            writer.EmitInstructionLocalVariable(OpCodeNumber.Stloc, methodBody.ReturnVariable);
            writer.EmitBranchingInstruction(OpCodeNumber.Br, methodBody.ReturnSequence);
        }