public static CodegenMethod From(
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope,
            Type expectedUnderlyingType,
            EventPropertyGetterSPI innerGetter,
            AccessType accessType,
            Type generator)
        {
            var methodNode = codegenMethodScope.MakeChild(
                accessType == AccessType.EXISTS ? typeof(bool) : typeof(object),
                generator,
                codegenClassScope)
                             .AddParam(typeof(object), "value");
            var block = methodNode.Block
                        .IfInstanceOf("value", typeof(EventBean))
                        .DeclareVarWCast(typeof(EventBean), "bean", "value");

            if (accessType == AccessType.GET)
            {
                block = block.BlockReturn(
                    innerGetter.EventBeanGetCodegen(Ref("bean"), codegenMethodScope, codegenClassScope));
            }
            else if (accessType == AccessType.EXISTS)
            {
                block = block.BlockReturn(
                    innerGetter.EventBeanExistsCodegen(Ref("bean"), codegenMethodScope, codegenClassScope));
            }
            else if (accessType == AccessType.FRAGMENT)
            {
                block = block.BlockReturn(
                    innerGetter.EventBeanFragmentCodegen(Ref("bean"), codegenMethodScope, codegenClassScope));
            }
            else
            {
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            block = block
                    .IfNotInstanceOf("value", expectedUnderlyingType)
                    .BlockReturn(
                accessType == AccessType.EXISTS
                        ? Constant(false)
                        : ConstantNull());

            CodegenExpression expression;

            if (accessType == AccessType.GET)
            {
                expression = innerGetter.UnderlyingGetCodegen(
                    Cast(expectedUnderlyingType, Ref("value")),
                    codegenMethodScope,
                    codegenClassScope);
            }
            else if (accessType == AccessType.EXISTS)
            {
                expression = innerGetter.UnderlyingExistsCodegen(
                    Cast(expectedUnderlyingType, Ref("value")),
                    codegenMethodScope,
                    codegenClassScope);
            }
            else if (accessType == AccessType.FRAGMENT)
            {
                expression = innerGetter.UnderlyingFragmentCodegen(
                    Cast(expectedUnderlyingType, Ref("value")),
                    codegenMethodScope,
                    codegenClassScope);
            }
            else
            {
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            block.MethodReturn(expression);
            return(methodNode);
        }