gpt4 book ai didi

c# - 如何将 IGroupMembersCollectionWithReferencesPage 从 Azure AD 转换为 C# 中的列表/集合?

转载 作者:行者123 更新时间:2023-12-02 07:38:00 25 4
gpt4 key购买 nike

我想将一个对象转换为列表,以便我可以迭代这些项目,如何做到这一点?成员变量返回 IGroupMembersCollectionWithReferencesPage。我怎样才能将其转换为列表?

var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);var graphClient = new GraphServiceClient(clientSecretCredential, 范围);

        try
{
// convert members to a list or collection
var members = await graphClient.Groups["group-id"].Members.Request().GetAsync();

return new JsonResult(members);
}
catch (Exception ex)
{
Logger.Warning(ex.Message);
throw;
}

最佳答案

To convert IGroupMembersCollectionWithReferencesPage from Azure AD to list, please try the below script mentioned in this SO Thread by user2250152 like below:

List<User> users = new List<User>();
var groupMembers = await Graph.Groups[groupId].Members.Request().GetAsync();
users.AddRange(groupMembers.CurrentPage.OfType<User>());
while(groupMembers.NextPageRequest!=null)
{
groupMembers = await groupMembers.NextPageRequest.GetAsync();
users.AddRange(groupMembers.CurrentPage.OfType<User>());
}

或者,您可以尝试在 SO Thread 中使用 Tony Ju 编写的以下脚本。 :

IGroupMembersCollectionWithReferencesPage lstOfAdusers =  graphServiceClient.Groups["groupID"].Members.Request().GetAsync().Result;

var memberoflist=graphServiceClient.Users["userID"].MemberOf.Request().GetAsync().Result;

请检查以下引用是否为您提供指导:

C# Azure AD Graph get all members of a group where are more than 20 by Tom Sun - MSFT

关于c# - 如何将 IGroupMembersCollectionWithReferencesPage 从 Azure AD 转换为 C# 中的列表/集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73047343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com