コード例 #1
0
        private CodegenExpression CodegenGet(
            Type requiredType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            if (returnType == null) {
                return ConstantNull();
            }

            var castTargetType = GetCodegenReturnType(requiredType);
            var useUnderlying = exprSymbol.IsAllowUnderlyingReferences &&
                                 !identNode.ResolvedPropertyName.Contains("?") &&
                                 !(eventType is WrapperEventType) &&
                                 !(eventType is VariantEventType);
            if (useUnderlying && !optionalEvent) {
                var underlying = exprSymbol.GetAddRequiredUnderlying(
                    codegenMethodScope,
                    streamNum,
                    eventType,
                    false);
                var property = propertyGetter.UnderlyingGetCodegen(underlying, codegenMethodScope, codegenClassScope);
                return CodegenLegoCast.CastSafeFromObjectType(castTargetType, property);
            }

            var method = codegenMethodScope.MakeChild(
                castTargetType, this.GetType(), codegenClassScope);
            var block = method.Block;

            if (useUnderlying) {
                var underlying = exprSymbol.GetAddRequiredUnderlying(
                    method,
                    streamNum,
                    eventType,
                    true);

                if (castTargetType.CanNotBeNull()) {
#if THROW_VALUE_ON_NULL
                    block.IfRefNullThrowException(underlying);
#else
                    block
                        .IfRefNull(underlying)
                        .BlockReturn(new CodegenExpressionDefault(castTargetType));
#endif
                }
                else {
                    block.IfRefNullReturnNull(underlying);
                }

                block.MethodReturn(
                    CodegenLegoCast.CastSafeFromObjectType(
                        castTargetType,
                        propertyGetter.UnderlyingGetCodegen(underlying, method, codegenClassScope)));
            }
            else {
                var refEPS = exprSymbol.GetAddEPS(method);
                method.Block.DeclareVar<EventBean>("@event", ArrayAtIndex(refEPS, Constant(streamNum)));
                if (optionalEvent) {
                    if (castTargetType.CanNotBeNull()) {
#if THROW_VALUE_ON_NULL
                        block.IfRefNullThrowException(Ref("@event"));
#else
                        block
                            .IfRefNull(Ref("@event"))
                            .BlockReturn(new CodegenExpressionDefault(castTargetType));
#endif
                    }
                    else {
                        block.IfRefNullReturnNull(Ref("@event"));
                    }
                }

                block.MethodReturn(
                    CodegenLegoCast.CastSafeFromObjectType(
                        castTargetType,
                        propertyGetter.EventBeanGetCodegen(Ref("@event"), method, codegenClassScope)));
            }

            return LocalMethod(method);
        }