Question

I am trying to get all the calendars a user has. The code I am using is:

LiveConnectClient liveClient = new LiveConnectClient( App.Session );
LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
dynamic result = operationResult.Result; 

When looking with the debugger into result I can see the calendars (keys and values). However I am having a problem extracting the information from this DynamicDictionary.

Was it helpful?

Solution 2

I managed to solve the issue and the code to do it (with some debug messages) is as follows:

try
{
    LiveConnectClient liveClient = new LiveConnectClient( App.Session );
    LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
    dynamic result = operationResult.Result;

    List<object> data = null;
    IDictionary<string, object> calendar = null;

    string msg = "Calendar names: ";
    Debug.WriteLine( msg );

    if ( operationResult.Result.ContainsKey( "data" ) )
    {
        data = (List<object>)operationResult.Result[ "data" ];
        for ( int i = 0 ; i < data.Count ; i++ )
        {
            calendar = (IDictionary<string, object>)data[ i ];
            if ( calendar.ContainsKey( "name" ) )
            {
                string Name = (string)calendar[ "name" ];
                string ID   = (string)calendar[ "id" ];
                msg = string.Format( "Name = {0}, ID = {1}", Name, ID );
                Debug.WriteLine( msg );
            }
        }
    }
}
catch ( LiveConnectException exception )
{
    Debug.WriteLine( "Error getting calendar info: " + exception.Message );
}

OTHER TIPS

It's just a dictionary. You should be able to do:

var item = result[key];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top