Skip to content

Commit 3f053cb

Browse files
committed
Update
1 parent 1c5e515 commit 3f053cb

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Generate-FunctionCommand.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ param(
2222

2323
[Parameter(Mandatory = $true)]
2424
[string]$ModelClassNameSpace,
25+
26+
[Parameter(Mandatory = $true)]
27+
[string]$FileOutputFolder,
2528

2629
[Parameter(Mandatory = $false)]
27-
[string]$FileOutputFolder = $null
30+
[System.Reflection.MethodInfo]$FriendMethodInfo
2831
)
2932

3033
. "$PSScriptRoot\Import-StringFunction.ps1";

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Import-TypeFunction.ps1

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ function Get-VerbTermNameAndSuffix
408408
[string]$MethodName
409409
)
410410

411-
$verb = $MethodName;
412-
$suffix = $null;
413-
411+
$found = $false;
414412
foreach ($key in $common_verb_mapping.Keys)
415413
{
416414
if ($MethodName.StartsWith($key))
@@ -426,11 +424,17 @@ function Get-VerbTermNameAndSuffix
426424
{
427425
$suffix += "WithDeallocation";
428426
}
429-
427+
$found = $true;
430428
break;
431429
}
432430
}
433431

432+
if (-not $found)
433+
{
434+
$verb = "Invoke";
435+
$suffix = $MethodName;
436+
}
437+
434438
Write-Output $verb;
435439
Write-Output $suffix;
436440
}
@@ -698,3 +702,44 @@ function Get-ProperTypeName
698702

699703
return $typeStr;
700704
}
705+
706+
# Check if 2 methods have the same parameter list
707+
function CheckIf-SameParameterList
708+
{
709+
param
710+
(
711+
[Parameter(Mandatory = $true)]
712+
[System.Reflection.MethodInfo]$methodInfo,
713+
714+
[Parameter(Mandatory = $true)]
715+
[System.Reflection.MethodInfo]$friendMethodInfo
716+
)
717+
718+
if ($methodInfo -eq $null -or $friendMethodInfo -eq $null)
719+
{
720+
return $false;
721+
}
722+
723+
$myParams = $methodInfo.GetParameters();
724+
$friendParams = $friendMethodInfo.GetParameters();
725+
if ($myParams.Count -ne $friendParams.Count)
726+
{
727+
return $false;
728+
}
729+
730+
for ($i = 0; $i -lt $myParams.Count -and $i -lt $friendParams.Count; $i++)
731+
{
732+
[System.Reflection.ParameterInfo]$paramInfo = $myParams[$i];
733+
[System.Reflection.ParameterInfo]$friendInfo = $friendParams[$i];
734+
if ($paramInfo.Name -ne $friendInfo.Name)
735+
{
736+
return $false;
737+
}
738+
elseif (-not $paramInfo.ParameterType.IsEquivalentTo($friendInfo.ParameterType))
739+
{
740+
return $false;
741+
}
742+
}
743+
744+
return $true;
745+
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ else
11721172

11731173
$qualified_methods = @();
11741174
$total_method_count = 0;
1175+
$friendMethodDict = @{};
11751176
foreach ($mtItem in $methods)
11761177
{
11771178
[System.Reflection.MethodInfo]$methodInfo = $mtItem;
@@ -1190,6 +1191,23 @@ else
11901191

11911192
$qualified_methods += $mtItem;
11921193
$total_method_count++;
1194+
1195+
# Handle Friend Methods
1196+
if ($mtItem.Name -eq 'Deallocate' -and (-not $friendMethodDict.ContainsKey($mtItem.Name)))
1197+
{
1198+
$methods2 = Get-OperationMethods $operation_type;
1199+
foreach ($friendMethodInfo in $methods2)
1200+
{
1201+
if ($friendMethodInfo.Name -eq 'PowerOff')
1202+
{
1203+
if (CheckIf-SameParameterList $methodInfo $friendMethodInfo)
1204+
{
1205+
$friendMethodDict.Add($mtItem.Name, $friendMethodInfo);
1206+
break;
1207+
}
1208+
}
1209+
}
1210+
}
11931211
}
11941212

11951213
$method_count = 0;
@@ -1218,10 +1236,12 @@ else
12181236
}
12191237
Write-Verbose $SEC_LINE;
12201238

1239+
$friendMethodInfo = $friendMethodDict[$methodInfo.Name];
12211240
$outputs = (. $PSScriptRoot\Generate-FunctionCommand.ps1 -OperationName $opShortName `
12221241
-MethodInfo $methodInfo `
12231242
-ModelClassNameSpace $client_model_namespace `
1224-
-FileOutputFolder $opOutFolder);
1243+
-FileOutputFolder $opOutFolder `
1244+
-FriendMethodInfo $friendMethodInfo);
12251245

12261246
if ($outputs.Count -ne $null)
12271247
{

0 commit comments

Comments
 (0)