Skip to content

Commit 64c8ded

Browse files
author
maddieclayton
committed
Address comments
1 parent 1afc57f commit 64c8ded

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs

+5-28
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ public List<T> TopLevelWildcardFilter<T>(string resourceGroupName, string name,
397397
if (HasProperty<T>("ResourceId") || HasProperty<T>("Id"))
398398
{
399399
string idProperty = HasProperty<T>("ResourceId") ? "ResourceId" : "Id";
400-
if (resourceGroupName != null)
400+
if (!string.IsNullOrEmpty(resourceGroupName))
401401
{
402402
WildcardPattern pattern = new WildcardPattern(resourceGroupName, WildcardOptions.IgnoreCase);
403403
output = output.Select(t => new { Id = new ResourceIdentifier((string) GetPropertyValue(t, idProperty)), Resource = t })
404404
.Where(p => IsMatch(p.Id, "ResourceGroupName", pattern))
405405
.Select(r => r.Resource);
406406
}
407407

408-
if (name != null)
408+
if (!string.IsNullOrEmpty(name))
409409
{
410410
WildcardPattern pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
411411
output = output.Select(t => new { Id = new ResourceIdentifier((string) GetPropertyValue(t, idProperty)), Resource = t })
@@ -417,14 +417,14 @@ public List<T> TopLevelWildcardFilter<T>(string resourceGroupName, string name,
417417
else
418418
{
419419
// if ResourceGroupName property, filter resource group
420-
if (HasProperty<T>("ResourceGroupName") && resourceGroupName != null)
420+
if (HasProperty<T>("ResourceGroupName") && !string.IsNullOrEmpty(resourceGroupName))
421421
{
422422
WildcardPattern pattern = new WildcardPattern(resourceGroupName, WildcardOptions.IgnoreCase);
423423
output = output.Where(t => IsMatch(t, "ResourceGroupName", pattern));
424424
}
425425

426426
// if Name property, filter name
427-
if (HasProperty<T>("Name") && name != null)
427+
if (HasProperty<T>("Name") && !string.IsNullOrEmpty(name))
428428
{
429429
WildcardPattern pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
430430
output = output.Where(t => IsMatch(t, "Name", pattern));
@@ -436,30 +436,7 @@ public List<T> TopLevelWildcardFilter<T>(string resourceGroupName, string name,
436436

437437
public List<T> SubResourceWildcardFilter<T>(string name, IEnumerable<T> resources)
438438
{
439-
IEnumerable<T> output = resources;
440-
if (HasProperty<T>("ResourceId") || HasProperty<T>("Id"))
441-
{
442-
string idProperty = HasProperty<T>("ResourceId") ? "ResourceId" : "Id";
443-
if (name != null)
444-
{
445-
WildcardPattern pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
446-
output = output.Select(t => new { Id = new ResourceIdentifier((string)GetPropertyValue(t, idProperty)), Resource = t })
447-
.Where(p => IsMatch(p.Id, "ResourceName", pattern))
448-
.Select(r => r.Resource);
449-
}
450-
451-
}
452-
else
453-
{
454-
// if Name property, filter name
455-
if (HasProperty<T>("Name") && name != null)
456-
{
457-
WildcardPattern pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
458-
output = output.Where(t => IsMatch(t, "Name", pattern));
459-
}
460-
}
461-
462-
return output.ToList();
439+
return TopLevelWildcardFilter(null, name, resources);
463440
}
464441

465442
private bool HasProperty<T>(string property)

0 commit comments

Comments
 (0)