Permalink
Browse files

C# lang.template polishing

  • Loading branch information...
1 parent 2e16a7b commit ae5a45707cc85b8dd2254bf3fbb6f871be5f3d45 @kuba-kubula kuba-kubula committed May 30, 2013
Showing with 19 additions and 21 deletions.
  1. +19 −21 csharp.html
View
40 csharp.html
@@ -1,30 +1,28 @@
<section name="csharp" class="csharp">
<p class="ioDesc">Request</p>
- <pre class="incoming"><code class="language-csharp">
-var request = System.Net.WebRequest.Create("<%= @apiUrl %><%= @url %>") as System.Net.HttpWebRequest;
-request.Method = "<%= @method.toUpperCase() %>";
+ <pre class="incoming"><code class="language-csharp">var request = System.Net.WebRequest.Create("<%= @apiUrl %><%= @url %>") as System.Net.HttpWebRequest;
+ request.Method = "<%= @method.toUpperCase() %>";
<% if @contentType: %>
-request.ContentType = "<%= @contentType %>";
+ request.ContentType = "<%= @contentType %>";
<% end %>
-<% if @headers: %>
-<% for header, value of @headers: %>request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>);
+<% if @headers and @helpers.isNotEmpty @headers: %>
+ <% for header, value of @headers: %>request.Headers.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>);
<% end %><% end %>
-<% if @helpers.isNotEmpty @body: %>
- <% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' or @method.toUpperCase() is 'DELETE': %>
+<% if @body?.length > 0: %>
+<% if @method.toUpperCase() is 'POST' or @method.toUpperCase() is 'PUT' or @method.toUpperCase() is 'DELETE' or @body.length > 0: %>
using (var writer = new System.IO.StreamWriter(request.GetRequestStream())) {
- byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(<%= @helpers.escape @body %>);
- request.ContentLength = byteArray.Length;
- writer.Write(byteArray);
- writer.Close();
- }
- <% end %>
- <% else: %>
- request.ContentLength = 0;
+ byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(<%= @helpers.escape @body %>);
+ request.ContentLength = byteArray.Length;
+ writer.Write(byteArray);
+ writer.Close();
+ }
+<% end %>
+<% else: %>
+ request.ContentLength = 0;
<% end %>
string responseContent;
using (var response = request.GetResponse() as System.Net.HttpWebResponse) {
- using (var reader = new System.IO.StreamReader(response.GetResponseStream())) {
- responseContent = reader.ReadToEnd();
- }
-}
-</code></pre></section>
+ using (var reader = new System.IO.StreamReader(response.GetResponseStream())) {
+ responseContent = reader.ReadToEnd();
+ }
+}</code></pre></section>

0 comments on commit ae5a457

Please sign in to comment.