Esempio n. 1
0
        public PropertySetterCodeGen(CodeGenerator cg, PropertyBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

            var method        = bindingInfo.propertyInfo.SetMethod;
            var propertyInfo  = this.bindingInfo.propertyInfo;
            var declaringType = propertyInfo.DeclaringType;
            var caller        = this.cg.AppendGetThisCS(method);
            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.Block())
            {
                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, {caller});");
            }
            this.cg.cs.AppendLine("return JSApi.JS_UNDEFINED;");
        }
Esempio n. 2
0
        public PropertyGetterCodeGen(CodeGenerator cg, PropertyBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

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

            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);
        }