Ejemplo n.º 1
0
        public override JsNode _Visit(IProperty pe)
        {
            var list = GetAccessorsToExport(pe);

            if (Sk.IsNativeProperty(pe))
            {
                var statements = new List <JsStatement>();

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

                var json = new JsJsonObjectExpression();
                foreach (var accessor in list)
                {
                    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 (Sk.IsNativePropertyEnumerable(pe))
                {
                    json.Add("enumerable", Js.True());
                }

                var defineStatement = Js.Member("Object").Member("defineProperty").Invoke(
                    ExportTypePrefix(pe.GetDeclaringTypeDefinition(), pe.IsStatic),
                    Js.String(pe.Name),
                    json).Statement();

                statements.Add(defineStatement);

                return(new JsUnit()
                {
                    Statements = statements
                });
            }
            else
            {
                var list2 = list.Select(ExportMethod).Cast <JsStatement>().ToList();
                return(new JsUnit {
                    Statements = list2
                });
            }
        }