AllTech
AllTech

Reputation: 603

Cannot operate on variables of type directoryObject, MS Graph API result

I am using below code to fetch the Manager details using Graph API.

var directoryObject = await graphServiceClient.Users[user.UserPrincipalName].Manager.Request().GetAsync();

I am trying to do something like below to access the values :

foreach(User user in directoryObject ){
    console.Writeline(user.DisplayName);
}

or even below doesn't work:

 console.Writeline(directoryObject.DisplayName);

But ,i am not able iterate over values . I have attached screenshot of the debug watch data of directoryObject.

Please help me in iterating over values of directoryObject or print entities in directoryObject by doing something like directoryObject.entityName i.e directoryObject.DisplayName enter image description here

Upvotes: 0

Views: 1186

Answers (1)

Ondrej Tucny
Ondrej Tucny

Reputation: 27962

The directoryObject apparently already is a User and not an IEnumerable<User> which would otherwise be required for the foreach to make sense. A simple typecast should work:

((User)directoryObject).DisplayName

Upvotes: 3

Related Questions