public List TopLevelWildcardFilter()

in src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs [469:520]


        public List<T> TopLevelWildcardFilter<T>(string resourceGroupName, string name, IEnumerable<T> resources)
        {
            IEnumerable<T> output = resources;
            if (HasProperty<T>("ResourceId") || HasProperty<T>("Id"))
            {
                string idProperty = HasProperty<T>("ResourceId") ? "ResourceId" : "Id";
                if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    WildcardPattern pattern = new WildcardPattern(resourceGroupName, WildcardOptions.IgnoreCase);
                    output = output.Select(t => new { Id = new ResourceIdentifier((string)GetPropertyValue(t, idProperty)), Resource = t })
                                   .Where(p => IsMatch(p.Id, "ResourceGroupName", pattern))
                                   .Select(r => r.Resource);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    string[] parts = name.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    List<WildcardPattern> patterns = new List<WildcardPattern>();
                    parts.ForEach(p => patterns.Add(new WildcardPattern(p, WildcardOptions.IgnoreCase)));
                    if (parts.Length == 1)
                    {
                        output = output.Select(t => new { Id = new ResourceIdentifier((string)GetPropertyValue(t, idProperty)), Resource = t })
                                     .Where(p => IsMatch(p.Id, "ResourceName", patterns.Last()))
                                     .Select(r => r.Resource);
                    }
                    else if (parts.Length == 2)
                    {
                        output = output.Select(t => new { Id = new ResourceIdentifier((string)GetPropertyValue(t, idProperty)), Resource = t })
                            .Where(p => IsMatch(p.Id, "ResourceName", patterns.Last()) && IsParentNameMatch(p.Id, patterns.First()))
                            .Select(r => r.Resource);
                    }
                }
            }
            else
            {
                // if ResourceGroupName property, filter resource group
                if (HasProperty<T>("ResourceGroupName") && !string.IsNullOrEmpty(resourceGroupName))
                {
                    WildcardPattern pattern = new WildcardPattern(resourceGroupName, WildcardOptions.IgnoreCase);
                    output = output.Where(t => IsMatch(t, "ResourceGroupName", pattern));
                }

                // if Name property, filter name
                if (HasProperty<T>("Name") && !string.IsNullOrEmpty(name))
                {
                    WildcardPattern pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
                    output = output.Where(t => IsMatch(t, "Name", pattern));
                }
            }

            return output.ToList();
        }