public string Type(string type, string[] genericArgs) { var useType = TypeFilter?.Invoke(type, genericArgs); if (useType != null) { return(useType); } if (genericArgs != null) { string cooked = null; if (type == "Nullable`1") { cooked = "{0}?".Fmt(GenericArg(genericArgs[0])); } else if (ArrayTypes.Contains(type)) { cooked = "{0}[]".Fmt(GenericArg(genericArgs[0])).StripNullable(); } else if (DictionaryTypes.Contains(type)) { cooked = "{{ [index: {0}]: {1}; }}".Fmt( GenericArg(genericArgs[0]), GenericArg(genericArgs[1])); } else { var parts = type.Split('`'); if (parts.Length > 1) { var args = StringBuilderCacheAlt.Allocate(); foreach (var arg in genericArgs) { if (args.Length > 0) { args.Append(", "); } args.Append(GenericArg(arg)); } var typeName = TypeAlias(type); cooked = "{0}<{1}>".Fmt(typeName, StringBuilderCacheAlt.ReturnAndFree(args)); } } if (cooked != null) { return(CookedTypeFilter?.Invoke(cooked) ?? cooked); } } else { type = type.StripNullable(); } return(TypeAlias(type)); }
private string TypeAlias(string type) { type = type.SanitizeType(); if (type == "Byte[]") { return(TypeAliases["Byte[]"]); } var arrParts = type.SplitOnFirst('['); if (arrParts.Length > 1) { return("{0}[]".Fmt(TypeAlias(arrParts[0]))); } TypeAliases.TryGetValue(type, out var typeAlias); var cooked = typeAlias ?? NameOnly(type); return(CookedTypeFilter?.Invoke(cooked) ?? cooked); }