コード例 #1
0
 private CodegenMethod NavigateMethodCodegen(
     CodegenMethodScope codegenMethodScope,
     CodegenClassScope codegenClassScope)
 {
     var navigateRecordMethod = NavigateRecordMethodCodegen(codegenMethodScope, codegenClassScope);
     return codegenMethodScope.MakeChild(typeof(GenericRecord), GetType(), codegenClassScope)
         .AddParam(typeof(GenericRecord), "record")
         .Block
         .DeclareVar<object>(
             "value",
             CodegenExpressionBuilder.StaticMethod(
                 typeof(AvroEventBeanGetterNestedIndexRooted),
                 "GetAtIndex",
                 CodegenExpressionBuilder.Ref("record"),
                 CodegenExpressionBuilder.Constant(_posTop.Name),
                 CodegenExpressionBuilder.Constant(_index)))
         .IfRefNullReturnNull("value")
         .MethodReturn(
             CodegenExpressionBuilder.LocalMethod(
                 navigateRecordMethod,
                 CodegenExpressionBuilder.CastRef(typeof(GenericRecord), "value")));
 }
コード例 #2
0
        private CodegenMethod NavigateRecordMethodCodegen(
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var block = codegenMethodScope.MakeChild(typeof(GenericRecord), GetType(), codegenClassScope)
                .AddParam(typeof(GenericRecord), "record")
                .Block
                .DeclareVar<GenericRecord>("current", CodegenExpressionBuilder.Ref("record"))
                .DeclareVarNull(typeof(object), "value");
            for (var i = 0; i < _nested.Length - 1; i++) {
                block.AssignRef(
                        "value",
                        _nested[i]
                            .UnderlyingGetCodegen(
                                CodegenExpressionBuilder.Ref("current"),
                                codegenMethodScope,
                                codegenClassScope))
                    .IfRefNotTypeReturnConst("value", typeof(GenericRecord), null)
                    .AssignRef("current", CodegenExpressionBuilder.CastRef(typeof(GenericRecord), "value"));
            }

            return block.MethodReturn(CodegenExpressionBuilder.Ref("current"));
        }