diff --git a/Rest.Net.Example/Program.cs b/Rest.Net.Example/Program.cs
index 1cf4a9f..67754f1 100644
--- a/Rest.Net.Example/Program.cs
+++ b/Rest.Net.Example/Program.cs
@@ -30,6 +30,7 @@ namespace MontoyaTech.Rest.Net.Example
}
}
+ [RouteTypeName("UserDto")]
public class User : BaseUser
{
public PlatformID MachineType;
diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj
index 0d9e867..b8249b8 100644
--- a/Rest.Net/Rest.Net.csproj
+++ b/Rest.Net/Rest.Net.csproj
@@ -17,7 +17,7 @@
MontoyaTech.Rest.Net
MontoyaTech.Rest.Net
True
- 1.4.5
+ 1.4.6
Logo_Symbol_Black_Outline.png
diff --git a/Rest.Net/RestCSharpClientGenerator.cs b/Rest.Net/RestCSharpClientGenerator.cs
index 7c81342..4393458 100644
--- a/Rest.Net/RestCSharpClientGenerator.cs
+++ b/Rest.Net/RestCSharpClientGenerator.cs
@@ -184,7 +184,9 @@ namespace MontoyaTech.Rest.Net
{
writer.WriteBreak();
- writer.Write($"public {(type.IsEnum ? "enum" : "class")} {type.Name}");
+ var newName = type.GetCustomAttribute();
+
+ writer.Write($"public {(type.IsEnum ? "enum" : "class")} {(newName != null ? newName.Name : type.Name)}");
if (type.IsEnum)
writer.Write(" : ").Write(this.GetTypeFullyResolvedName(Enum.GetUnderlyingType(type)));
@@ -193,7 +195,7 @@ namespace MontoyaTech.Rest.Net
writer.NewLine().WriteLine("{").Indent();
- FieldInfo[] fields = null;
+ FieldInfo[] fields;
if (type.IsEnum)
fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
diff --git a/Rest.Net/RestClientGenerator.cs b/Rest.Net/RestClientGenerator.cs
index ef85e7a..d45fe80 100644
--- a/Rest.Net/RestClientGenerator.cs
+++ b/Rest.Net/RestClientGenerator.cs
@@ -285,12 +285,21 @@ namespace MontoyaTech.Rest.Net
{
var builder = new StringBuilder();
- int genericSymbol = type.Name.IndexOf('`');
+ var newName = type.GetCustomAttribute();
- if (genericSymbol == -1)
- builder.Append(type.Name);
+ if (newName != null)
+ {
+ builder.Append(newName.Name);
+ }
else
- builder.Append(type.Name.Substring(0, genericSymbol));
+ {
+ int genericSymbol = type.Name.IndexOf('`');
+
+ if (genericSymbol == -1)
+ builder.Append(type.Name);
+ else
+ builder.Append(type.Name.Substring(0, genericSymbol));
+ }
var genericArguments = type.GetGenericArguments();
diff --git a/Rest.Net/RouteTypeName.cs b/Rest.Net/RouteTypeName.cs
new file mode 100644
index 0000000..0aec94d
--- /dev/null
+++ b/Rest.Net/RouteTypeName.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MontoyaTech.Rest.Net
+{
+ ///
+ /// The outline of an attribute that can be used to rename a type when it's used in routes.
+ ///
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
+ public class RouteTypeName : Attribute
+ {
+ ///
+ /// The new name for this type.
+ ///
+ public string Name;
+
+ public RouteTypeName(string name)
+ {
+ this.Name = name;
+ }
+ }
+}