diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
index 883a635472d..87d55ab3f6e 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
@@ -10,7 +10,6 @@ using System.Net;
using System.Text;
using Newtonsoft.Json;
using RestSharp;
-using RestSharp.Extensions;
namespace {{packageName}}.Client
{
@@ -171,7 +170,7 @@ namespace {{packageName}}.Client
/// Escaped string.
public string EscapeString(string str)
{
- return RestSharp.Extensions.StringExtensions.UrlEncode(str);
+ return UrlEncode(str);
}
///
@@ -183,9 +182,9 @@ namespace {{packageName}}.Client
public FileParameter ParameterToFile(string name, Stream stream)
{
if (stream is FileStream)
- return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
+ return FileParameter.Create(name, ReadAsBytes(stream), Path.GetFileName(((FileStream)stream).Name));
else
- return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
+ return FileParameter.Create(name, ReadAsBytes(stream), "no_file_name_provided");
}
///
@@ -365,6 +364,62 @@ namespace {{packageName}}.Client
public static dynamic ConvertType(dynamic source, Type dest) {
return Convert.ChangeType(source, dest);
}
+
+ ///
+ /// Convert stream to byte array
+ /// Credit/Ref: http://stackoverflow.com/a/221941/677735
+ ///
+ /// Input stream to be converted
+ /// Byte array
+ public static byte[] ReadAsBytes(Stream input)
+ {
+ byte[] buffer = new byte[16*1024];
+ using (MemoryStream ms = new MemoryStream())
+ {
+ int read;
+ while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ ms.Write(buffer, 0, read);
+ }
+ return ms.ToArray();
+ }
+ }
+
+ ///
+ /// URL encode a string
+ /// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
+ ///
+ /// String to be URL encoded
+ /// Byte array
+ public static string UrlEncode(string input)
+ {
+ const int maxLength = 32766;
+
+ if (input == null)
+ {
+ throw new ArgumentNullException("input");
+ }
+
+ if (input.Length <= maxLength)
+ {
+ return Uri.EscapeDataString(input);
+ }
+
+ StringBuilder sb = new StringBuilder(input.Length * 2);
+ int index = 0;
+
+ while (index < input.Length)
+ {
+ int length = Math.Min(input.Length - index, maxLength);
+ string subString = input.Substring(index, length);
+
+ sb.Append(Uri.EscapeDataString(subString));
+ index += subString.Length;
+ }
+
+ return sb.ToString();
+ }
+
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
index 049c1ef74d8..36217fde02d 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
@@ -10,7 +10,6 @@ using System.Net;
using System.Text;
using Newtonsoft.Json;
using RestSharp;
-using RestSharp.Extensions;
namespace IO.Swagger.Client
{
@@ -171,7 +170,7 @@ namespace IO.Swagger.Client
/// Escaped string.
public string EscapeString(string str)
{
- return RestSharp.Extensions.StringExtensions.UrlEncode(str);
+ return UrlEncode(str);
}
///
@@ -183,9 +182,9 @@ namespace IO.Swagger.Client
public FileParameter ParameterToFile(string name, Stream stream)
{
if (stream is FileStream)
- return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
+ return FileParameter.Create(name, ReadAsBytes(stream), Path.GetFileName(((FileStream)stream).Name));
else
- return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
+ return FileParameter.Create(name, ReadAsBytes(stream), "no_file_name_provided");
}
///
@@ -369,6 +368,62 @@ namespace IO.Swagger.Client
public static dynamic ConvertType(dynamic source, Type dest) {
return Convert.ChangeType(source, dest);
}
+
+ ///
+ /// Convert stream to byte array
+ /// Credit/Ref: http://stackoverflow.com/a/221941/677735
+ ///
+ /// Input stream to be converted
+ /// Byte array
+ public static byte[] ReadAsBytes(Stream input)
+ {
+ byte[] buffer = new byte[16*1024];
+ using (MemoryStream ms = new MemoryStream())
+ {
+ int read;
+ while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ ms.Write(buffer, 0, read);
+ }
+ return ms.ToArray();
+ }
+ }
+
+ ///
+ /// URL encode a string
+ /// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
+ ///
+ /// String to be URL encoded
+ /// Byte array
+ public static string UrlEncode(string input)
+ {
+ const int maxLength = 32766;
+
+ if (input == null)
+ {
+ throw new ArgumentNullException("input");
+ }
+
+ if (input.Length <= maxLength)
+ {
+ return Uri.EscapeDataString(input);
+ }
+
+ StringBuilder sb = new StringBuilder(input.Length * 2);
+ int index = 0;
+
+ while (index < input.Length)
+ {
+ int length = Math.Min(input.Length - index, maxLength);
+ string subString = input.Substring(index, length);
+
+ sb.Append(Uri.EscapeDataString(subString));
+ index += subString.Length;
+ }
+
+ return sb.ToString();
+ }
+
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
index c292bea9bad..c975e54d4be 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
index f63c1d21fe3..5c1092d07fc 100644
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
index 286fb333c48..3ed0e98c4f7 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
+++ b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
@@ -1,8 +1,8 @@
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
-/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
+/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
index c292bea9bad..c975e54d4be 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
index f63c1d21fe3..5c1092d07fc 100644
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb differ