Files
PowerShell/src/System.Management.Automation/engine/MshReference.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

92 lines
2.7 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Dynamic;
using System.Management.Automation.Language;
using System.Runtime.CompilerServices;
namespace System.Management.Automation
{
/// <summary>
/// Define type for a reference object in Monad scripting language.
/// </summary>
/// <remarks>
/// This class is used to describe both kinds of references:
/// a. reference to a value: _value will be holding the value being referenced.
/// b. reference to a variable: _value will be holding a PSVariable instance for the variable to be referenced.
///
/// A reference is created in following ways,
/// a. value reference
/// $a = [ref] 3
/// [ref] $a = 3
/// [ref] $a = $b
/// b. variable reference
/// $a = [ref] $b
/// </remarks>
public class PSReference
{
private object _value;
/// <summary>
/// Create an instance of PSReference.
/// </summary>
/// <param name="value"></param>
public PSReference(object value)
{
_value = value;
}
/// <summary>
/// Get and set value of PSReference.
/// </summary>
/// <remarks>
/// If underlining object is a value, the object itself will be operated on.
/// If underlining object is a variable, the variable will be operated on.
/// </remarks>
public object Value
{
get
{
PSVariable variable = _value as PSVariable;
if (variable != null)
{
return variable.Value;
}
return _value;
}
set
{
PSVariable variable = _value as PSVariable;
if (variable != null)
{
variable.Value = value;
return;
}
_value = value;
}
}
internal static readonly CallSite<Func<CallSite, object, object, object>> CreatePsReferenceInstance =
CallSite<Func<CallSite, object, object, object>>.Create(PSCreateInstanceBinder.Get(new CallInfo(1), null));
internal static PSReference CreateInstance(object value, Type typeOfValue)
{
Type psReferType = typeof(PSReference<>).MakeGenericType(typeOfValue);
return (PSReference)CreatePsReferenceInstance.Target.Invoke(CreatePsReferenceInstance, psReferType, value);
}
}
internal class PSReference<T> : PSReference
{
public PSReference(object value) : base(value)
{
}
}
}