public bool IsAdmin(Microsoft.Graph.IUserMemberOfCollectionWithReferencesPage mygroups) { bool result = false; SortedDictionary <string, string> groups = new SortedDictionary <string, string>(); groups = GroupsToDictionary(groups, mygroups); foreach (KeyValuePair <string, string> kvp in groups) { if (kvp.Key.Contains("_admin")) { result = true; } } return(result); }
public SortedDictionary <string, string> GroupsToDictionary(SortedDictionary <string, string> groups, Microsoft.Graph.IUserMemberOfCollectionWithReferencesPage mygroups) { foreach (var group in mygroups) { var properties = group.GetType().GetProperties(); string name = ""; string id = ""; foreach (var child in properties) { if (child.Name == "DisplayName" || child.Name == "Id") { object value = child.GetValue(group); string stringRepresentation; if (!(value is string) && value is IEnumerable <string> ) { stringRepresentation = "[" + string.Join(", ", (value as IEnumerable <string>).OfType <object>().Select(c => c.ToString())) + "]"; } else { stringRepresentation = value?.ToString(); } if (child.Name == "DisplayName") { name = stringRepresentation; } else if (child.Name == "Id") { id = stringRepresentation; } } } if (name != "" && id != "") { if (!groups.ContainsKey(name)) { groups.Add(name, id); } } } return(groups); }