Пример #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);},   })");
        }
        JsMemberExpression ExportTypePrefix(ITypeDefinition ce, bool isStatic)
        {
            var me = Js.Members(GetJsTypeName(ce));

            if (!isStatic)
            {
                me = me.MemberOrSelf(Sk.GetPrototypeName(ce));
            }
            return(me);
        }
Пример #3
0
        protected override JsUnit OnAfterExportType(ITypeDefinition ce, JsClrType jsType)
        {
            var extJsType = new ExtJsType
            {
                extend  = jsType.baseTypeName,
                statics = jsType.staticDefinition,
            };
            //if (extJsType.extend == "System.Object")
            //    extJsType.extend = null;
            var json = (JsJsonObjectExpression)Serialize(extJsType);

            //var ctor = json.NamesValues.Where(t => t.Name.Name == "ctor").FirstOrDefault();
            if (jsType.definition == null)
            {
                jsType.definition = new JsObject();
            }
            var ctor = jsType.definition.TryGetValue("ctor");

            if (ctor != null)
            {
                jsType.definition.Remove("ctor");
                jsType.definition.Add("constructor", ctor);
                //ctor.Name.Name = "constructor";
                //var func = ctor.Value as JsFunction;
                //if (func != null)
                //{
                //    func.Block.Statements.Insert(0, Js.This().Member("callSuper").Invoke(Js.Member("arguments")).Statement());
                //}
            }
            foreach (var me in jsType.definition)
            {
                var name  = me.Key;
                var value = (JsExpression)me.Value;
                if (json.NamesValues == null)
                {
                    json.NamesValues = new List <JsJsonNameValue>();
                }
                json.NamesValues.Add(new JsJsonNameValue {
                    Name = new JsJsonMember {
                        Name = name
                    }, Value = value
                });
            }

            var define = Js.Members("Ext.define").Invoke(Js.String(jsType.fullname), json).Statement();
            var unit   = new JsUnit {
                Statements = new List <JsStatement> {
                    define
                }
            };

            return(unit);// base.OnAfterExportType(ce, jsType);
        }
        public override JsNode _VisitEnum(ITypeDefinition ce)
        {
            var unit = new JsUnit {
                Statements = new List <JsStatement>()
            };

            ExportTypeNamespace(unit, ce);
            var json     = VisitEnumToJson(ce);
            var typeName = GetJsTypeName(ce);
            var st       = Js.Members(typeName).Assign(json).Statement();

            unit.Statements.Add(st);
            return(unit);
        }
Пример #5
0
        public static JsExpression EntityTypeRefToMember(IType typeRef, bool isGenericArgument)
        {
            if (typeRef == null)
            {
                return(null);
            }
            if (typeRef.Kind == TypeKind.Anonymous)
            {
                return(Js.Null());
            }
            if (isGenericArgument)
            {
                var code = Sk.GetGenericArugmentJsCode(typeRef.GetEntityType());
                if (code != null)
                {
                    return(Js.CodeExpression(code));
                }
            }
            var name = GetEntityJsName(typeRef);

            if (Sk.IsJsonMode(typeRef.GetEntityType()))
            {
                return(Js.String(name));
            }
            var member = Js.Members(name);

            if (typeRef.IsGenericTypeParameter())
            {
                if (member.PreviousMember == null)
                {
                    member.PreviousMember = Js.This();
                }
                else
                {
                    throw new Exception();
                }
            }
            var def = typeRef.GetDefinitionOrArrayType();

            if (def != null && Sk.IsClrType(def))
            {
                member = member.Member("ctor");
            }
            return(member);
        }
 public override JsNode ExportConstructor(IMethod ctor)
 {
     if (ctor.IsStatic)
     {
         var globaImporter = CreateGlobalMemberConverter();
         var node2         = globaImporter.ExportConstructor(ctor);
         return(node2);
     }
     else
     {
         var func     = (JsFunction)base.ExportConstructor(ctor);
         var fullname = GetJsTypeName(ctor.GetDeclaringTypeDefinition());
         if (fullname.Contains("."))
         {
             var st = Js.Members(fullname).Assign(func).Statement();
             return(st);
         }
         else
         {
             return(Js.Var(fullname, func).Statement());
         }
     }
 }