예제 #1
0
        public string ToString(AzureResourceSegment segment, int resourceCount = 0)
        {
            resourceCount = Math.Max(resourceCount, 0);
            resourceCount = Math.Min(resourceCount, ResourceTypes.Count);

            var resourceId = new StringBuilder($"/subscriptions/{SubscriptionId}");

            if (segment != AzureResourceSegment.Subscription && !string.IsNullOrEmpty(ResourceGroup))
            {
                resourceId.Append($"/resourceGroups/{ResourceGroup}");

                if (segment != AzureResourceSegment.ResourceGroup && ResourceTypes.Any())
                {
                    for (int i = 0; i < (resourceCount == 0 ? ResourceTypes.Count : resourceCount); i++)
                    {
                        if (i == 0)
                        {
                            resourceId.Append($"/providers/{ResourceNamespace}");
                        }

                        resourceId.Append($"/{ResourceTypes[i].Key}/{ResourceTypes[i].Value}");
                    }
                }
            }

            return(resourceId.ToString());
        }