Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generated request parameters value types should be nullable to reflec…
…t their absence on the querystring
  • Loading branch information
Mpdreamz committed Jan 9, 2018
commit 927e3df17b120b932e06570ffbadc87113fb14fd
16 changes: 13 additions & 3 deletions src/CodeGeneration/ApiGenerator/Domain/ApiQueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class ApiQueryParameters
public string Obsolete { get; set; }
public IEnumerable<string> Options { get; set; }



public string CsharpType(string paramName)
{
switch (this.Type)
Expand Down Expand Up @@ -86,10 +84,22 @@ public string HighLevelType(string paramName)
return csharpType;
}
}
private static string NullableCsharpType(string fieldType)
{
switch (fieldType)
{
case "bool": return "bool?";
case "integer": return "int?";
case "double": return "double?";
case "long": return "long?";
default:
return fieldType;
}
}

public Func<string, string, string, string, string> Generator { get; set; } =
(fieldType, mm, original, setter) =>
$"public {fieldType} {mm} {{ get {{ return Q<{fieldType}>(\"{original}\"); }} set {{ Q(\"{original}\", {setter}); }} }}";
$"public {NullableCsharpType(fieldType)} {mm} {{ get {{ return Q<{NullableCsharpType(fieldType)}>(\"{original}\"); }} set {{ Q(\"{original}\", {setter}); }} }}";

public Func<string, string, string, string, string> FluentGenerator { get; set; }

Expand Down