예제 #1
0
        public PropertySetterCodeGen(CodeGenerator cg, PropertyBindingInfo propertyBindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = propertyBindingInfo;

            var method        = propertyBindingInfo.propertyInfo.SetMethod;
            var propertyInfo  = this.bindingInfo.propertyInfo;
            var declaringType = propertyInfo.DeclaringType;
            var caller        = this.cg.AppendGetThisCS(method, false);
            var propertyType  = this.cg.bindingManager.GetCSTypeFullName(propertyInfo.PropertyType);

            this.cg.cs.AppendLine("{0} value;", propertyType);
            var getter = this.cg.bindingManager.GetScriptObjectGetter(propertyInfo.PropertyType, "ctx", "arg_val", "value");

            this.cg.cs.AppendLine("if (!{0})", getter);
            using (this.cg.cs.CodeBlockScope())
            {
                this.cg.cs.AppendLine("throw new ParameterException(typeof({0}), 0);", propertyType);
            }
            this.cg.cs.AppendLine("{0}.{1} = value;", caller, propertyInfo.Name);
            if (declaringType.IsValueType && !method.IsStatic)
            {
                // 非静态结构体属性修改, 尝试替换实例
                this.cg.cs.AppendLine($"js_rebind_this(ctx, this_obj, ref {caller});");
            }
            this.cg.cs.AppendLine("return JSApi.JS_UNDEFINED;");
        }
예제 #2
0
        public PropertyGetterCodeGen(CodeGenerator cg, PropertyBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

            var caller = this.cg.AppendGetThisCS(bindingInfo.propertyInfo.GetMethod, false);

            this.cg.cs.AppendLine("var ret = {0}.{1};", caller, bindingInfo.propertyInfo.Name);
            var pusher = this.cg.AppendValuePusher(bindingInfo.propertyInfo.PropertyType, "ret");

            this.cg.cs.AppendLine("return {0};", pusher);
        }