Skip to content

Commit dc3bd28

Browse files
committed
Fix merge conflict
2 parents 1a28f1f + fc4871c commit dc3bd28

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

RestSharp.Tests/JsonTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ public void Can_Deserialize_With_Default_Root_Alternative_Culture()
324324
}
325325
}
326326

327+
[Fact]
328+
public void Can_Deserialize_Names_With_Underscore_Prefix()
329+
{
330+
var data = File.ReadAllText(Path.Combine("SampleData", "underscore_prefix.txt"));
331+
var response = new RestResponse { Content = data };
332+
var json = new JsonDeserializer();
333+
json.RootElement = "User";
334+
335+
var output = json.Deserialize<SOUser>(response);
336+
337+
Assert.Equal("John Sheehan", output.DisplayName);
338+
Assert.Equal(1786, output.Id);
339+
}
340+
327341
[Fact]
328342
public void Can_Deserialize_Names_With_Underscores_With_Default_Root()
329343
{

RestSharp.Tests/RestSharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
114114
</Content>
115115
<Content Include="SampleData\iso8601datetimes.txt">
116+
<Content Include="SampleData\underscore_prefix.txt">
116117
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117118
</Content>
118119
<Content Include="SampleData\datetimes.txt">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"User":{
3+
"_id":1786,
4+
"_displayName":"John Sheehan",
5+
"Reputation":18332,
6+
"CreationDate":1219071163,
7+
"_displayName":"John Sheehan",
8+
"EmailHash":"lkdsafadfjsadfkjlsdjflkjdsf",
9+
"Age":"28",
10+
"LastAccessDate":1269715453,
11+
"WebsiteUrl":"http://john-sheehan.com/blog",
12+
"Location":"Minnesota",
13+
"AboutMe":"<h2><a href=\"http://twitter.com/johnsheehan\" rel=\"nofollow\">Follow me on Twitter</a></h2>\r\n\r\n<h2><a href=\"http://john-sheehan.com/blog\" rel=\"nofollow\">Read my blog</a></h2>\r\n\r\n<h2>Visit <a href=\"http://managedassembly.com\" rel=\"nofollow\">managedassembly.com</a> - A community for .NET developers.</h2>\r\n\r\n<p>I am the founder of <a href=\"http://rimsystems.com\" rel=\"nofollow\">RIM Systems</a>, maker of <a href=\"http://snapleague.com\" rel=\"nofollow\">SnapLeague</a>, a web-based league management system for recreational athletics.</p>",
14+
"Views":1639,
15+
"UpVotes":1665,
16+
"DownVotes":427
17+
}
18+
}

RestSharp/Extensions/StringExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ public static string AddDashes(this string pascalCasedWord)
309309
"$1-$2"), @"[\s]", "-");
310310
}
311311

312+
/// <summary>
313+
/// Add an undescore prefix to a pascasl-cased string
314+
/// </summary>
315+
/// <param name="pascalCasedWord"></param>
316+
/// <returns></returns>
317+
public static string AddUnderscorePrefix(this string pascalCasedWord)
318+
{
319+
return string.Format("_{0}", pascalCasedWord);
320+
}
321+
312322
/// <summary>
313323
/// Return possible variants of a name for name matching.
314324
/// </summary>
@@ -339,6 +349,12 @@ public static IEnumerable<string> GetNameVariants(this string name, CultureInfo
339349

340350
// try name with dashes with lower case
341351
yield return name.AddDashes().ToLower(culture);
352+
353+
// try name with underscore prefix
354+
yield return name.AddUnderscorePrefix();
355+
356+
// try name with underscore prefix, using camel case
357+
yield return name.ToCamelCase(culture).AddUnderscorePrefix();
342358
}
343359
}
344360
}

0 commit comments

Comments
 (0)