Ejemplo n.º 1
0
        public static CodegenExpression CodegenDateTime(
            CalendarSetForge forge,
            CodegenExpression dateTime,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var field = forge.field;
            var methodNode = codegenMethodScope
                .MakeChild(typeof(DateTime), typeof(CalendarSetForgeOp), codegenClassScope)
                .AddParam(typeof(DateTime), "dateTime");
            var evaluationType = forge.valueExpr.EvaluationType;

            methodNode.Block
                .DeclareVar<int?>(
                    "value",
                    SimpleNumberCoercerFactory.CoercerInt.CoerceCodegenMayNull(
                        forge.valueExpr.EvaluateCodegen(evaluationType, methodNode, exprSymbol, codegenClassScope),
                        evaluationType,
                        methodNode,
                        codegenClassScope))
                .IfRefNull("value")
                .BlockReturn(Ref("dateTime"))
                .MethodReturn(
                    ExprDotMethod(
                        Ref("dateTime"),
                        "SetFieldValue",
                        EnumValue(field),
                        Unbox<int?>(Ref("value"))));
            return LocalMethod(methodNode, dateTime);
        }
Ejemplo n.º 2
0
        public static CodegenExpression CodegenCalendar(
            CalendarSetForge forge,
            CodegenExpression dateTimeEx,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var field = Constant(forge.field);
            var evaluationType = forge.valueExpr.EvaluationType;
            if (evaluationType.CanNotBeNull()) {
                var valueExpr = forge.valueExpr
                    .EvaluateCodegen(evaluationType, codegenMethodScope, exprSymbol, codegenClassScope);
                return ExprDotMethod(dateTimeEx, "SetFieldValue", field, valueExpr);
            }
            else {
                var methodNode = codegenMethodScope
                    .MakeChild(typeof(void), typeof(CalendarSetForgeOp), codegenClassScope)
                    .AddParam(typeof(DateTimeEx), "dtx");
                var valueExpr = forge.valueExpr
                    .EvaluateCodegen(evaluationType, methodNode, exprSymbol, codegenClassScope);

                methodNode.Block
                    .DeclareVar<int?>(
                        "value",
                        SimpleNumberCoercerFactory.CoercerInt.CoerceCodegenMayNull(
                            valueExpr,
                            forge.valueExpr.EvaluationType,
                            methodNode,
                            codegenClassScope))
                    .IfRefNullReturnNull("value")
                    .Expression(
                        ExprDotMethod(
                            dateTimeEx,
                            "SetFieldValue",
                            field,
                            Unbox<int?>(Ref("value"))))
                    .MethodEnd();
                return LocalMethod(methodNode, dateTimeEx);
            }
        }