Convert dynamic type to list

I am using Facebook SDK to get the data. I want to use parallel.foreach

but cannot use it - instead an error occurs:

It is not possible to use a lambda expression as an argument for a dynamically dispatched operation without first injecting it into the delegate or expression tree class

So is it possible to transform the data received into a list?

dynamic friends = app.Get("me/friends");   
Parallel.ForEach(friends.data, friendsData =>
    {
        Interlocked.Increment(ref infoCount);
        LoadFriends(friend, infoCount);
    });

      

+1


source to share


2 answers


If you can't use a lambda expression, have you tried the anonymous method?



dynamic friends = app.Get("me/friends");   
    Parallel.ForEach(friends.data, delegate(dynamic friendsData)
       {
           Interlocked.Increment(ref infoCount);
           LoadFriends(friend, infoCount);

       });

      

+3


source


I used the following code to convert JsonArray to dictionary id as key and names as value



var friendlist = (friends.data as Facebook.JsonArray).ToDictionary( 
                p => (p as Facebook.JsonObject)["id"].ToString(), 
                p => (p as Facebook.JsonObject)["name"].ToString());

Parallel.ForEach(friendlist, friend
       {
           Interlocked.Increment(ref infoCount);
           LoadFriends(friend, infoCount);
       }

      

+1


source







All Articles