Example #1
0
 public static JsJsonObjectExpression Add(this JsJsonObjectExpression exp, JsJsonNameValue nameValue)
 {
     if (exp.NamesValues == null)
     {
         exp.NamesValues = new List <JsJsonNameValue>();
     }
     exp.NamesValues.Add(nameValue);
     return(exp);
 }
Example #2
0
 void _Visit(JsJsonObjectExpression node)
 {
     if (node.NamesValues.IsNullOrEmpty())
     {
         Control("{}");
     }
     else
     {
         BeginBlock();
         VisitEachJoin(node.NamesValues, (first) =>
         {
         }, (prev, next) =>
         {
             Comma();
         }, (last) =>
         {
         });
         EndBlock();
     }
 }
 protected virtual void _visit( JsJsonObjectExpression node )
 {
     throw new NotImplementedException( "JsJsonObjectExpression" );
 }
Example #4
0
 public static JsJsonObjectExpression Add(this JsJsonObjectExpression exp, string name, JsExpression value)
 {
     exp.Add(JsonNameValue(name, value));
     return(exp);
 }
Example #5
0
 protected JsJsonObjectExpression VisitEnumToJson(ITypeDefinition ce)
 {
     bool valuesAsNames;
     Sk.UseJsonEnums(ce, out valuesAsNames);
     //var valuesAsNames = att != null && att.ValuesAsNames;
     var constants = ce.GetConstants().ToList();
     if (!valuesAsNames && constants.Where(t => t.ConstantValue == null).FirstOrDefault() != null)
     {
         var value = 0L;
         foreach (var c in constants)
         {
             if (c.ConstantValue == null)
                 c.SetConstantValue(value);
             else
                 value = Convert.ToInt64(c.ConstantValue);
             value++;
         }
     }
     constants.RemoveAll(t => !Sk.IsJsExported(t));
     var json = new JsJsonObjectExpression { NamesValues = new List<JsJsonNameValue>() };
     json.NamesValues.AddRange(constants.Select(t => VisitEnumField(t, valuesAsNames)));
     return json;
 }
 protected override void _visit(JsJsonObjectExpression node)
 {
     if ( node != null && node.NamesValues != null )
     {
         foreach ( JsJsonNameValue nameValue in node.NamesValues )
         {
             visit( nameValue );
         }
     }
 }
        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 };
            }
        }