File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using Newtonsoft . Json . Linq ;
5
+ using RedditSharp . Interfaces ;
6
+
7
+ namespace RedditSharp
8
+ {
9
+ public partial class Helpers
10
+ {
11
+ internal static List < T > PopulateObjects < T > ( JToken json , IWebAgent webAgent )
12
+ where T : ISettableWebAgent , new ( )
13
+ {
14
+ if ( json . Type != JTokenType . Array )
15
+ throw new ArgumentException ( "must be of type array" , nameof ( json ) ) ;
16
+
17
+ var objects = new List < T > ( ) ;
18
+
19
+ for ( var i = 0 ; i < json . Count ( ) ; i ++ )
20
+ {
21
+ var item = new T ( ) ;
22
+ PopulateObject ( json [ i ] , item ) ;
23
+ item . WebAgent = webAgent ;
24
+ objects . Add ( item ) ;
25
+ }
26
+
27
+ return objects ;
28
+ }
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ using Newtonsoft . Json ;
2
+
3
+ namespace RedditSharp . Interfaces
4
+ {
5
+ internal interface ISettableWebAgent
6
+ {
7
+ [ JsonIgnore ]
8
+ IWebAgent WebAgent { set ; }
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments