In C# how to enumerate IEnumerable or FuncAsyncPageable or PageResponseEnumerator?

Viewed 45

I am new to C#. I am trying to get a list of subscriptions from an azure message bus:

ServiceBusAdministrationClient client = new ServiceBusAdministrationClient(connectionString);

var getSubResponse = client.GetSubscriptionsAsync(topicPath);
Console.WriteLine("subs:" + getSubResponse.AsPages());

The response is of type Task<IEnumerable<SubscriptionDescription>> or AsyncPageable<SubscriptionProperties>, depending on which documentation you read.

Visual Studio says the response type is Azure.Core.PageResponseEnumerator.FuncAsyncPageable<Azure.Messaging.ServiceBus.Administration.SubscriptionProperties>

How do I write some C# code to display every value in the response?

If I look at the response in Visual Studio debugger, it has hundreds of nested fields, none of which are the actual subscription info, they are just pointers etc. There is a Non-Public members field with _pageFunc, and below this are "Method" and "Target" and under target is another pageFunc which also has Method and Target.

Any ideas how I get useful info form such an object?

1 Answers

Ok, found the answer, its this:

        var getSubResponse = client.GetSubscriptionsAsync(topicPath);

        await foreach (var sub in getSubResponse)
        {
            Console.WriteLine("sub name:" + sub.SubscriptionName);
            Console.WriteLine("sub ttl:" + sub.DefaultMessageTimeToLive);
            Console.WriteLine("sub max delivery count:" + sub.MaxDeliveryCount);
        }

There does not seem to be a way to dump all the fields unfortunately.

Related