mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
committed by
Jason Shirk
parent
e71d003749
commit
916ef56eeb
@@ -6568,9 +6568,16 @@ namespace System.Management.Automation.Language
|
||||
var codeMethod = methodInfo as PSCodeMethod;
|
||||
if (codeMethod != null)
|
||||
{
|
||||
return new DynamicMetaObject(
|
||||
InvokeMethod(codeMethod.CodeReference, null, args.Prepend(target).ToArray(), false, MethodInvocationType.Ordinary)
|
||||
.Cast(typeof(object)), restrictions).WriteToDebugLog(this);
|
||||
Expression expr = InvokeMethod(codeMethod.CodeReference, null, args.Prepend(target).ToArray(), false, MethodInvocationType.Ordinary);
|
||||
if (codeMethod.CodeReference.ReturnType == typeof(void))
|
||||
{
|
||||
expr = Expression.Block(expr, ExpressionCache.AutomationNullConstant);
|
||||
}
|
||||
else
|
||||
{
|
||||
expr = expr.Cast(typeof(object));
|
||||
}
|
||||
return new DynamicMetaObject(expr, restrictions).WriteToDebugLog(this);
|
||||
}
|
||||
|
||||
var parameterizedProperty = methodInfo as PSParameterizedProperty;
|
||||
|
||||
@@ -79,6 +79,39 @@ Describe "Adapter Tests" -tags "CI" {
|
||||
$val = $doc.ToString()
|
||||
$val | Should Be "book"
|
||||
}
|
||||
|
||||
It "Calls CodeMethod with void result" {
|
||||
|
||||
class TestCodeMethodInvokationWithVoidReturn {
|
||||
[int] $CallCounter
|
||||
|
||||
static [int] IntMethodCM([PSObject] $self) {
|
||||
return $self.CallCounter
|
||||
}
|
||||
|
||||
static [void] VoidMethodCM([PSObject] $self) {
|
||||
$self.CallCounter++
|
||||
}
|
||||
|
||||
static [Reflection.MethodInfo] GetMethodInfo([string] $name) {
|
||||
return [TestCodeMethodInvokationWithVoidReturn].GetMethod($name)
|
||||
}
|
||||
}
|
||||
|
||||
Update-TypeData -Force -TypeName TestCodeMethodInvokationWithVoidReturn -MemberType CodeMethod -MemberName IntMethod -Value ([TestCodeMethodInvokationWithVoidReturn]::GetMethodInfo('IntMethodCM'))
|
||||
Update-TypeData -Force -TypeName TestCodeMethodInvokationWithVoidReturn -MemberType CodeMethod -MemberName VoidMethod -Value ([TestCodeMethodInvokationWithVoidReturn]::GetMethodInfo('VoidMethodCM'))
|
||||
try {
|
||||
$o = [TestCodeMethodInvokationWithVoidReturn]::new()
|
||||
$o.CallCounter | Should Be 0
|
||||
$o.VoidMethod()
|
||||
$o.CallCounter | Should be 1
|
||||
|
||||
$o.IntMethod() | Should be 1
|
||||
}
|
||||
finally {
|
||||
Remove-TypeData TestCodeMethodInvokationWithVoidReturn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Adapter XML Tests" -tags "CI" {
|
||||
|
||||
Reference in New Issue
Block a user