Пример #1
0
        protected virtual void onGenButton(Button button, bool isRootComponent, CodeMemberField field, CodeMemberProperty prop)
        {
            CodeAttributeDeclaration autoCompo = field.CustomAttributes.OfType <CodeAttributeDeclaration>()
                                                 .FirstOrDefault(a => a.AttributeType.BaseType == typeof(AutoCompoAttribute).Name);

            //是按钮
            if (controllerType == CTRL_TYPE_BUTTON && button == buttonMain)
            {
                autoCompo.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression("mainButton")));
            }
            string name = prop.Name;

            name = name.headToUpper();
            //事件
            CodeMemberEvent Event;

            if ((controllerType == CTRL_TYPE_BUTTON && button == buttonMain) ||
                isRootComponent)
            {
                Event = genEvent(typeof(Action).Name, "onClick", Codo.type(_type.Name));
            }
            else
            {
                Event = genEvent(typeof(Action).Name, "on" + name + "Click", Codo.type(_type.Name));
            }
            //回调函数
            CodeMemberMethod callbackMethod;

            if ((controllerType == CTRL_TYPE_BUTTON && button == buttonMain) || isRootComponent)
            {
                callbackMethod = genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), "clickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            else
            {
                callbackMethod = genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), name + "ClickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            //注册
            _initMethod.Statements.Add(Codo.getField(field.Name).getProp(NAME_OF_ONCLICK)
                                       .getMethod(NAME_OF_ADDLISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
            //注销
            _clearMethod.Statements.Add(Codo.getField(field.Name).getProp(NAME_OF_ONCLICK)
                                        .getMethod(NAME_OF_REMOVELISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
        }
Пример #2
0
        public override void onGen(AutoCompoGenerator generator, Button component, bool isRootComponent, AutoBindFieldInfo info, CodeMemberField field)
        {
            string name = field.Name.Substring(2, field.Name.Length - 2);

            name = name.headToUpper();
            //事件
            CodeMemberEvent Event;

            if (isRootComponent)
            {
                Event = generator.genEvent(typeof(Action).Name, "onClick", Codo.type(generator.type.Name));
            }
            else
            {
                Event = generator.genEvent(typeof(Action).Name, "on" + name + "Click", Codo.type(generator.type.Name));
            }
            //回调函数
            CodeMemberMethod callbackMethod;

            if (isRootComponent)
            {
                callbackMethod = generator.genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), "clickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            else
            {
                callbackMethod = generator.genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), name + "ClickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            //注册
            generator.initMethod.Statements.Add(Codo.getField(field.Name).getProp(AutoCompoGenerator.NAME_OF_ONCLICK)
                                                .getMethod(AutoCompoGenerator.NAME_OF_ADDLISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
            //注销
            generator.clearMethod.Statements.Add(Codo.getField(field.Name).getProp(AutoCompoGenerator.NAME_OF_ONCLICK)
                                                 .getMethod(AutoCompoGenerator.NAME_OF_REMOVELISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
        }