Skip to content

Commit 2f6e434

Browse files
committed
Merge pull request #155 from primaryobjects/master
Fixed Shortlink from throwing exception if Comment.Parent is null.
2 parents df4b6a8 + ae60491 commit 2f6e434

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

RedditSharp/Things/Comment.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ public override string Shortlink
122122
{
123123
get
124124
{
125-
// Not really a "short" link, but you can't actually use short links for comments
125+
// Not really a "short" link, but you can't actually use short links for comments
126+
string linkId = "";
127+
int index = this.LinkId.IndexOf('_');
128+
if (index > -1)
129+
{
130+
linkId = this.LinkId.Substring(index + 1);
131+
}
132+
126133
return String.Format("{0}://{1}/r/{2}/comments/{3}/_/{4}",
127-
RedditSharp.WebAgent.Protocol, RedditSharp.WebAgent.RootDomain,
128-
this.Subreddit, this.Parent.Id, this.Id);
134+
RedditSharp.WebAgent.Protocol, RedditSharp.WebAgent.RootDomain,
135+
this.Subreddit, this.Parent != null ? this.Parent.Id : linkId, this.Id);
129136
}
130137
}
131138

0 commit comments

Comments
 (0)