void Visit(TsTypeRef tr) { if (tr.AnonymousCallSignature != null) { Visit(tr.AnonymousCallSignature); return; } _Writer .Write(((TsTypeRef)tr).Name) .VisitEachJoinIfNotNullOrEmpty(tr.GenericArguments, "<", ",", ">"); }
public static bool IsNullOrVoid(this TsTypeRef tr) { return(tr == null || tr.Name == "void"); }
private TsTypeRef Visit(IType type) { if(type==null) return new TsTypeRef { Name = "void" }; var typeDef = type.GetDefinition(); if (typeDef!=null) { var ktc = typeDef.KnownTypeCode; if(ktc != KnownTypeCode.None) { if (ktc==KnownTypeCode.Void) return new TsTypeRef { Name = "void" }; else if (ktc== KnownTypeCode.Object) return new TsTypeRef { Name = "any" }; else if (ktc == KnownTypeCode.String) return new TsTypeRef { Name = "string" }; else if (ktc == KnownTypeCode.Boolean) return new TsTypeRef { Name = "boolean" }; else if (ktc == KnownTypeCode.Int32 || ktc == KnownTypeCode.Int32 || ktc == KnownTypeCode.Int16 || ktc == KnownTypeCode.Int64 || ktc == KnownTypeCode.Double || ktc == KnownTypeCode.Single || ktc == KnownTypeCode.SByte || ktc == KnownTypeCode.Byte || ktc == KnownTypeCode.UInt16 || ktc == KnownTypeCode.UInt32 || ktc == KnownTypeCode.UInt64 || ktc == KnownTypeCode.Decimal ) return new TsTypeRef { Name = "number" }; } if (Sk.IsJsonMode(typeDef)) return new TsTypeRef { Name = "Object" }; if (type.Kind == TypeKind.Delegate && !Sk.IsJsExported(type.GetDefinition())) { var func = Visit(type.GetDelegateInvokeMethod()); func.Name = null; func.IsCallSignature = true; return new TsTypeRef { AnonymousCallSignature = func}; } } var tr2 = new TsTypeRef { Name = SkJs.GetEntityJsName(type) }; tr2.GenericArguments = type.TypeArguments.Select(Visit).ToList(); if (tr2.Name == "Array" && tr2.GenericArguments.Count == 0) { tr2.GenericArguments.Add(new TsTypeRef { Name = "any" }); } return tr2; }