Ejemplo n.º 1
0
        public virtual List <JEntityDeclaration> _Visit(IProperty pe)
        {
            var list = GetAccessorsToExport(pe);

            if (JMeta.IsNativeProperty(pe))
            {
                var statements = new List <JStatement>();

                statements.AddRange(list.Select(ExportMethod).Cast <JStatement>());

                var json = new JJsonObjectExpression();
                foreach (var accessor in list)
                {
                    //if (accessor == pe.Getter) json.Add("get", (JsFunction)ExportMethod(accessor));
                    //if (accessor == pe.Setter) json.Add("set", (JsFunction)ExportMethod(accessor));
                    if (accessor == pe.Getter)
                    {
                        json.Add("get", ExportTypePrefix(pe.Getter.GetDeclaringTypeDefinition(), pe.IsStatic).Member("get_" + pe.Name));
                    }
                    if (accessor == pe.Setter)
                    {
                        json.Add("set", ExportTypePrefix(pe.Setter.GetDeclaringTypeDefinition(), pe.IsStatic).Member("set_" + pe.Name));
                    }
                }
                if (JMeta.IsNativePropertyEnumerable(pe))
                {
                    json.Add("enumerable", new JCodeExpression()
                    {
                        Code = "true"
                    });
                }
                //json.Add("configurable", new JsCodeExpression() { Code = "true" });

                var defineStatement = new JExpressionStatement()
                {
                    Expression = new JInvocationExpression()
                    {
                        Member = new JMemberExpression()
                        {
                            Name = "Object.defineProperty"
                        },
                        Arguments = new List <JExpression>(new JExpression[]
                        {
                            ExportTypePrefix(pe.GetDeclaringTypeDefinition(), pe.IsStatic),
                            new JStringExpression()
                            {
                                Value = pe.Name
                            },
                            json
                        })
                    }
                };

                statements.Add(defineStatement);
                throw new NotSupportedException();
                //return new JsUnit() { Statements = statements };
            }
            else
            {
                var list2 = list.Select(ExportMethod).ToList();
                return(list2.SelectMany(t => t).ToList());
            }
        }