Files
PowerShell/src/System.Management.Automation/engine/interpreter/DynamicInstructionN.cs
T
Steve Lee 4af3068566 Code cleanup: Add space after closing brace where needed (#8530)
* Update TestService

* Update WebListener

* Update Controllers

* Update ExpTest

* Update MyApp

* Update Logic

* Update Logic

* Update MyApp

* Update Microsoft.Management.Infrastructure.CimCmdlets

* Update Microsoft.PowerShell.Commands.Diagnostics

* Update Microsoft.PowerShell.ScheduledJob

* Update Microsoft.WSMan.Management

* Update Microsoft.WSMan.Runtime

* Update ResGen

* Update TypeCatalogGen

* Update commands

* Update Eventing

* Update Reader

* Update utility

* Update ShowCommand

* Update trace

* Update WebCmdlet

* Update Common

* Update CoreCLR

* Update common

* Update format-object

* Update format-wide

* Update out-file

* Update out-printer

* Update out-string

* Update OutGridView

* Update LocalAccounts

* Update Commands

* Update security

* Update CoreCLR

* Update DscSupport

* Update engine

* Update help

* Update logging

* Update namespaces

* Update security

* Update utils

* Update config

* Update perfCounters

* Update tracing

* Update cmdletization

* Update other

* Update cim

* Update xml

* Update CoreCLR

* Update common

* Update DefaultFormatters

* Update out-console

* Update out-textInterface

* Update DisplayDatabase

* Update Utilities

* Update COM

* Update ComInterop

* Update CommandCompletion

* Update debugger

* Update ExperimentalFeature

* Update hostifaces

* Update interpreter

* Update lang

* Update Modules

* Update parser

* Update runtime

* Update client

* Update commands

* Update common

* Update fanin

* Update server

* Update WireDataFormat

* Update Binding

* Update Operations

* Update interface

* Update cmdletization

* Update cim

* Update management

* Update WindowsTaskbarJumpList

* Update msh
2018-12-24 11:20:06 +05:00

79 lines
2.6 KiB
C#

/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Apache License, Version 2.0, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Apache License, Version 2.0.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/
using System.Runtime.CompilerServices;
namespace System.Management.Automation.Interpreter
{
internal sealed partial class DynamicInstructionN : Instruction
{
private readonly CallInstruction _target;
private readonly object _targetDelegate;
private readonly CallSite _site;
private readonly int _argumentCount;
private readonly bool _isVoid;
public DynamicInstructionN(Type delegateType, CallSite site)
{
var methodInfo = delegateType.GetMethod("Invoke");
var parameters = methodInfo.GetParameters();
_target = CallInstruction.Create(methodInfo, parameters);
_site = site;
_argumentCount = parameters.Length - 1;
_targetDelegate = site.GetType().GetField("Target").GetValue(site);
}
public DynamicInstructionN(Type delegateType, CallSite site, bool isVoid)
: this(delegateType, site)
{
_isVoid = isVoid;
}
public override int ProducedStack { get { return _isVoid ? 0 : 1; } }
public override int ConsumedStack { get { return _argumentCount; } }
public override int Run(InterpretedFrame frame)
{
int first = frame.StackIndex - _argumentCount;
object[] args = new object[1 + _argumentCount];
args[0] = _site;
for (int i = 0; i < _argumentCount; i++)
{
args[1 + i] = frame.Data[first + i];
}
object ret = _target.InvokeInstance(_targetDelegate, args);
if (_isVoid)
{
frame.StackIndex = first;
}
else
{
frame.Data[first] = ret;
frame.StackIndex = first + 1;
}
return 1;
}
public override string ToString()
{
return "DynamicInstructionN(" + _site + ")";
}
}
}