Exemple #1
0
        public static string From(
            ICodegenContext context,
            Type expectedUnderlyingType,
            EventPropertyGetterSPI innerGetter,
            AccessType accessType,
            Type generator)
        {
            var block = context.AddMethod(accessType == AccessType.EXISTS ? typeof(bool) : typeof(object),
                                          typeof(object), "value", generator)
                        .IfNotInstanceOf("value", expectedUnderlyingType)
                        .IfInstanceOf("value", typeof(EventBean))
                        .DeclareVarWCast(typeof(EventBean), "bean", "value");

            switch (accessType)
            {
            case AccessType.GET:
                block = block.BlockReturn(innerGetter.CodegenEventBeanGet(Ref("bean"), context));
                break;

            case AccessType.EXISTS:
                block = block.BlockReturn(innerGetter.CodegenEventBeanExists(Ref("bean"), context));
                break;

            case AccessType.FRAGMENT:
                block = block.BlockReturn(innerGetter.CodegenEventBeanFragment(Ref("bean"), context));
                break;

            default:
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            block = block.BlockReturn(Constant(accessType == AccessType.EXISTS ? (object)false : null));

            ICodegenExpression expression;

            switch (accessType)
            {
            case AccessType.GET:
                expression = innerGetter.CodegenUnderlyingGet(Cast(
                                                                  expectedUnderlyingType, Ref("value")), context);
                break;

            case AccessType.EXISTS:
                expression = innerGetter.CodegenUnderlyingExists(Cast(
                                                                     expectedUnderlyingType, Ref("value")), context);
                break;

            case AccessType.FRAGMENT:
                expression = innerGetter.CodegenUnderlyingFragment(
                    Cast(expectedUnderlyingType, Ref("value")), context);
                break;

            default:
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            return(block.MethodReturn(expression));
        }