How to Cast IMember as IPublishedContent OR Models Builder Typed Version of Member

I know that MembershipHelper is no longer a thing in V9. But I need to get a list of all members of a certain role. So I am using the dreaded memberservice _memberService.FindMembersInRole() to this. That all is returning fine however, now for the life of me I can’t cast IMember to either IPublishedContent Or the strongly typed version of that member type. Everything works until the cast happens, and then its cast to Null…

How can I cast an IMember to either IPublishedContent or the Modelsbuilder version of that IPub?

        var model = new AdminDashboardViewModel();
        var allAdvisors = _memberService.FindMembersInRole("Advisors", "", matchType: Umbraco.Cms.Core.Persistence.Querying.StringPropertyMatchType.StartsWith);
        if (allAdvisors?.Any() ?? false)
        {
            List<IPublishedContent> advisorList = new List<IPublishedContent>();
            foreach (var advisor in allAdvisors)
            {
                IPublishedContent castAdvisor = advisor as IPublishedContent;
                advisorList.Add(castAdvisor);
            }
            model.Advisors = advisorList;
        }

and my ViewModel…

public class AdminDashboardViewModel
{
    public List<IPublishedContent> Advisors { get; set; }
}

Do I need to do a lookup based on the IMember ID? There’s got to be a better way!


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/108746-how-to-cast-imember-as-ipublishedcontent-or-models-builder-typed-version-of-member