Exemplo n.º 1
0
        public override JsNode _VisitDelegate(ITypeDefinition ce)
        {
            var CurrentType = new JsClrType {
                Kind = JsClrTypeKind.Delegate
            };

            CurrentType.fullname = GetJsTypeName(ce);

            //Generate constructor
            var genericParams = new List <ITypeParameter>(ce.GetGenericArguments());
            var func          = new JsFunction();

            func.Parameters = genericParams.Select(t => t.Name).ToList();
            func.Parameters.Add("obj");
            func.Parameters.Add("func");
            func.Block = Js.Block();
            foreach (var ga in genericParams)
            {
                func.Block.Add(Js.This().Member(ga.Name).Assign(Js.Member(ga.Name)).Statement());
            }
            func.Block.Add(Js.Members("System.MulticastDelegate.ctor.call").Invoke(Js.This(), Js.Member("obj"), Js.Member("func")).Statement());
            CurrentType.GetDefinition(false)["ctor"] = func;
            return(OnAfterExportType(ce, CurrentType));
            //return func;

            //FullName',{ ShortName:function(T1,T2,T3,...,obj,func){this.T1=T1;....;this.construct(obj,func);},   })");
        }
Exemplo n.º 2
0
 private void ImportToType(JsClrType ce, List <EntityToJsNode> mappings)
 {
     foreach (var map in mappings)
     {
         if (map.JsNode == null)
         {
             continue;
         }
         var isStatic = map.Entity.IsStatic();
         var def      = ce.GetDefinition(isStatic);
         List <JsJsonNameValue> pairs;
         if (map.JsNode is JsNodeList)
         {
             pairs = ((JsNodeList)map.JsNode).Nodes.Cast <JsJsonNameValue>().ToList();
         }
         else
         {
             pairs = new List <JsJsonNameValue> {
                 (JsJsonNameValue)map.JsNode
             }
         };
         foreach (var pair in pairs)
         {
             if (pair == null)
             {
                 throw new CompilerException(map.Entity, "Export of entity is null");
             }
             var name = pair.Name.Name;
             //if (def[name] != pair.Value)
             //    throw new Exception();
             def[name] = pair.Value;
         }
     }
 }
Exemplo n.º 3
0
        public override JsNode _VisitEnum(ITypeDefinition ce)
        {
            var CurrentType = new JsClrType {
                Kind = JsClrTypeKind.Enum
            };

            CurrentType.fullname = GetJsTypeName(ce);
            var json = VisitEnumToJson(ce);

            foreach (var item in json.NamesValues)
            {
                ////TODO: baseType (long, byte, etc...)
                //foreach (var pe in ce.GetConstants())
                //{
                //var name = pe.Name;
                CurrentType.GetDefinition(true)[item.Name.Name] = item.Value;
                //  }
            }
            return(OnAfterExportType(ce, CurrentType));
        }