Permalink
Browse files

Add PreTypeFilter to all generated types

  • Loading branch information...
mythz committed Aug 1, 2018
1 parent f0be77f commit 79b79c480e0dade10b3794b25d405abf313e144c
@@ -20,6 +20,8 @@ public CSharpGenerator(MetadataTypesConfig config)
Config = config;
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static Dictionary<string, string> TypeAliases = new Dictionary<string, string>
{
@@ -235,6 +237,8 @@ private string AppendType(ref StringBuilderWrapper sb, MetadataType type, string
var typeAccessor = !Config.MakeInternal ? "public" : "internal";
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
sb.AppendLine($"{typeAccessor} enum {Type(type.Name, type.GenericArgs)}");
@@ -23,6 +23,8 @@ public DartGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static List<string> DefaultImports = new List<string>
{
// "dart:collection", Required for inheriting List<T> / ListBase
@@ -356,6 +358,8 @@ public string GetCode(MetadataTypes metadata, IRequest request, INativeTypesMeta
AppendAttributes(sb, type.Attributes);
AppendDataContract(sb, type.DataContract);
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
var enumType = Type(type.Name, type.GenericArgs);
@@ -20,6 +20,8 @@ public FSharpGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static Dictionary<string, string> TypeAliases = new Dictionary<string, string>
{
};
@@ -190,6 +192,8 @@ public string GetCode(MetadataTypes metadata, IRequest request)
sb.AppendLine("[<GeneratedCode(\"AddServiceStackReference\", \"{0}\")>]".Fmt(Env.VersionString));
}
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
sb.AppendLine("type {0} =".Fmt(Type(type.Name, type.GenericArgs)));
@@ -20,6 +20,8 @@ public JavaGenerator(MetadataTypesConfig config)
Config = config;
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static string DefaultGlobalNamespace = "dtos";
public static List<string> DefaultImports = new List<string>
@@ -294,6 +296,8 @@ private List<string> RemoveIgnoredTypes(MetadataTypes metadata)
var typeName = Type(type.Name, type.GenericArgs);
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
sb.AppendLine("public static enum {0}".Fmt(typeName));
@@ -22,6 +22,8 @@ public KotlinGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static List<string> DefaultImports = new List<string>
{
/* built-in types used
@@ -281,6 +283,8 @@ private List<string> RemoveIgnoredTypes(MetadataTypes metadata)
var typeName = Type(type.Name, type.GenericArgs);
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
var hasIntValue = type.EnumNames.Count == (type.EnumValues?.Count ?? 0);
@@ -22,6 +22,8 @@ public SwiftGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static List<string> DefaultImports = new List<string>
{
"Foundation",
@@ -244,6 +246,8 @@ private List<string> RemoveIgnoredTypes(MetadataTypes metadata)
AppendAttributes(sb, type.Attributes);
AppendDataContract(sb, type.DataContract);
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
sb.AppendLine($"public enum {Type(type.Name, type.GenericArgs)} : Int");
@@ -20,6 +20,8 @@ public TypeScriptGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static List<string> DefaultImports = new List<string>
{
};
@@ -245,6 +247,8 @@ public string GetCode(MetadataTypes metadata, IRequest request, INativeTypesMeta
AppendAttributes(sb, type.Attributes);
AppendDataContract(sb, type.DataContract);
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
if (type.IsEnumInt.GetValueOrDefault() || type.EnumNames.IsEmpty())
@@ -21,6 +21,8 @@ public VbNetGenerator(MetadataTypesConfig config)
feature = HostContext.GetPlugin<NativeTypesFeature>();
}
public static Action<StringBuilderWrapper, MetadataType> PreTypeFilter { get; set; }
public static Dictionary<string, string> TypeAliases = new Dictionary<string, string>
{
{"Int16", "Short"},
@@ -273,6 +275,8 @@ private string AppendType(ref StringBuilderWrapper sb, MetadataType type, string
if (Config.AddGeneratedCodeAttributes)
sb.AppendLine("<GeneratedCode(\"AddServiceStackReference\", \"{0}\")>".Fmt(Env.VersionString));
PreTypeFilter?.Invoke(sb, type);
if (type.IsEnum.GetValueOrDefault())
{
sb.AppendLine("Public Enum {0}".Fmt(Type(type.Name, type.GenericArgs)));
@@ -23,6 +23,7 @@
using ServiceStack.IO;
using ServiceStack.MiniProfiler;
using ServiceStack.MiniProfiler.Data;
using ServiceStack.NativeTypes.CSharp;
using ServiceStack.OrmLite;
using ServiceStack.ProtoBuf;
using ServiceStack.Razor;
@@ -48,6 +49,14 @@ public AppHost()
public override void Configure(Container container)
{
// EnableBuffering();
CSharpGenerator.PreTypeFilter = (sb, type) =>
{
if (!type.IsEnum.GetValueOrDefault() && !type.IsInterface.GetValueOrDefault())
{
sb.AppendLine("[Serializable]");
}
};
this.CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/Views/TestErrorNotFound");

0 comments on commit 79b79c4

Please sign in to comment.