Skip to content

Commit 0c5326d

Browse files
committed
Implement #188.
1 parent 64eb015 commit 0c5326d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

RedditSharp/Things/Thing.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace RedditSharp.Things
1010
/// </summary>
1111
public class Thing : RedditObject
1212
{
13-
13+
1414
#region Properties
1515

1616
/// <summary>
@@ -42,6 +42,16 @@ public class Thing : RedditObject
4242
/// Gets the time since last fetch from reddit servers.
4343
/// </summary>
4444
public TimeSpan TimeSinceFetch => DateTime.Now - FetchedAt;
45+
46+
private JToken RawJson { get; set; }
47+
48+
/// <summary>
49+
/// Gets a property of this Thing, without any automatic conversion.
50+
/// </summary>
51+
/// <param name="property">The reddit API name of the property</param>
52+
/// <returns>The property's value as a <see cref="String"/> or null if the property
53+
/// doesn't exist or is null.</returns>
54+
public String this[String property] => RawJson[property].ValueOrDefault<string>();
4555
#endregion
4656

4757

@@ -68,6 +78,7 @@ internal void Populate(JToken json)
6878
FullName = data["name"].ValueOrDefault<string>();
6979
Id = data["id"].ValueOrDefault<string>();
7080
Kind = json["kind"].ValueOrDefault<string>();
81+
RawJson = data;
7182
FetchedAt = DateTime.Now;
7283
Helpers.PopulateObject(GetJsonData(json), this);
7384
}
@@ -177,8 +188,10 @@ protected virtual async Task<JToken> SimpleActionAsync(string endpoint)
177188
/// <param name="fullname">FullName of thing to act on. eg. t1_66666</param>
178189
/// <param name="endpoint">URL to post to</param>
179190
/// <returns></returns>
180-
protected static Task<JToken> SimpleActionAsync(IWebAgent agent, string fullname, string endpoint ) {
181-
return agent.Post(endpoint, new {
191+
protected static Task<JToken> SimpleActionAsync(IWebAgent agent, string fullname, string endpoint)
192+
{
193+
return agent.Post(endpoint, new
194+
{
182195
id = fullname
183196
});
184197
}

0 commit comments

Comments
 (0)