mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-18 05:05:36 +00:00
This change moves powershell to .NET Core 2.0. Major changes are: 1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`. 2. Refactor code to remove most CLR stub types and extension types. 3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed. 4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded). 5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this. 6. Replace the use of some APIs with the ones that take `SecureString`. 7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12. 8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
214 lines
7.1 KiB
C#
214 lines
7.1 KiB
C#
/********************************************************************++
|
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
--********************************************************************/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace System.Management.Automation
|
|
{
|
|
/// <summary>
|
|
/// Represents a parameter declaration that can be constructed at runtime.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Instances of <see cref="RuntimeDefinedParameterDictionary"/>
|
|
/// should be returned to cmdlet implementations of
|
|
/// <see cref="IDynamicParameters.GetDynamicParameters"/>.
|
|
///
|
|
/// It is permitted to subclass <see cref="RuntimeDefinedParameter"/>
|
|
/// but there is no established scenario for doing this, nor has it been tested.
|
|
/// </remarks>
|
|
/// <seealso cref="RuntimeDefinedParameterDictionary"/>
|
|
/// <seealso cref="IDynamicParameters"/>
|
|
/// <seealso cref="IDynamicParameters.GetDynamicParameters"/>
|
|
public class RuntimeDefinedParameter
|
|
{
|
|
/// <summary>
|
|
/// Constructs a runtime-defined parameter instance.
|
|
/// </summary>
|
|
public RuntimeDefinedParameter()
|
|
{
|
|
} // RuntimeDefinedParameter
|
|
|
|
/// <summary>
|
|
/// Constructs a new instance of a runtime-defined parameter using the specified parameters.
|
|
/// </summary>
|
|
///
|
|
/// <param name="name">
|
|
/// The name of the parameter. This cannot be null or empty.
|
|
/// </param>
|
|
///
|
|
/// <param name="parameterType">
|
|
/// The type of the parameter value. Arguments will be coerced to this type before binding.
|
|
/// This parameter cannot be null.
|
|
/// </param>
|
|
///
|
|
/// <param name="attributes">
|
|
/// Any parameter attributes that should be on the parameter. This can be any of the
|
|
/// parameter attributes including but not limited to Validate*Attribute, ExpandWildcardAttribute, etc.
|
|
/// </param>
|
|
///
|
|
/// <exception cref="ArgumentException">
|
|
/// If <paramref name="name"/> is null or empty.
|
|
/// </exception>
|
|
///
|
|
/// <exception cref="ArgumentNullException">
|
|
/// If <paramref name="parameterType"/> is null.
|
|
/// </exception>
|
|
public RuntimeDefinedParameter(string name, Type parameterType, Collection<Attribute> attributes)
|
|
{
|
|
if (String.IsNullOrEmpty(name))
|
|
{
|
|
throw PSTraceSource.NewArgumentException("name");
|
|
}
|
|
|
|
if (parameterType == null)
|
|
{
|
|
throw PSTraceSource.NewArgumentNullException("parameterType");
|
|
}
|
|
|
|
_name = name;
|
|
_parameterType = parameterType;
|
|
|
|
if (attributes != null)
|
|
{
|
|
Attributes = attributes;
|
|
}
|
|
} // RuntimeDefinedParameter
|
|
|
|
/// <summary>
|
|
/// Gets or sets the name of the parameter
|
|
/// </summary>
|
|
///
|
|
/// <exception cref="ArgumentException">
|
|
/// If <paramref name="value"/> is null or empty on set.
|
|
/// </exception>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return _name;
|
|
}
|
|
set
|
|
{
|
|
if (String.IsNullOrEmpty(value))
|
|
{
|
|
throw PSTraceSource.NewArgumentException("name");
|
|
}
|
|
_name = value;
|
|
}
|
|
} // Name
|
|
private string _name = String.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the type of the parameter.
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// Arguments will be coerced to this type before being bound.
|
|
/// </remarks>
|
|
///
|
|
/// <exception cref="ArgumentNullException">
|
|
/// If <paramref name="value"/> is null.
|
|
/// </exception>
|
|
public Type ParameterType
|
|
{
|
|
get
|
|
{
|
|
return _parameterType;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
throw PSTraceSource.NewArgumentNullException("value");
|
|
}
|
|
_parameterType = value;
|
|
}
|
|
}
|
|
private Type _parameterType;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the parameter.
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// If the value is set prior to parameter binding, the value will be
|
|
/// reset before each pipeline object is processed.
|
|
/// </remarks>
|
|
public object Value
|
|
{
|
|
get
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.IsSet = true;
|
|
_value = value;
|
|
}
|
|
}
|
|
private object _value;
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether this parameter value has been set.
|
|
/// </summary>
|
|
public bool IsSet { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the attribute collection that describes the parameter.
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// This can be any attribute that can be applied to a normal parameter.
|
|
/// </remarks>
|
|
public Collection<Attribute> Attributes { get; } = new Collection<Attribute>();
|
|
} // class RuntimeDefinedParameter
|
|
|
|
/// <summary>
|
|
/// Represents a collection of runtime-defined parameters that are keyed based on the name
|
|
/// of the parameter.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Instances of <see cref="RuntimeDefinedParameterDictionary"/>
|
|
/// should be returned to cmdlet implementations of
|
|
/// <see cref="IDynamicParameters.GetDynamicParameters"/>.
|
|
///
|
|
/// It is permitted to subclass <see cref="RuntimeDefinedParameterDictionary"/>
|
|
/// but there is no established scenario for doing this, nor has it been tested.
|
|
/// </remarks>
|
|
/// <seealso cref="RuntimeDefinedParameter"/>
|
|
/// <seealso cref="IDynamicParameters"/>
|
|
/// <seealso cref="IDynamicParameters.GetDynamicParameters"/>
|
|
[Serializable]
|
|
public class RuntimeDefinedParameterDictionary : Dictionary<string, RuntimeDefinedParameter>
|
|
{
|
|
/// <summary>
|
|
/// Constructs a new instance of a runtime-defined parameter dictionary.
|
|
/// </summary>
|
|
public RuntimeDefinedParameterDictionary()
|
|
: base(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
} // ctor
|
|
|
|
/// <summary>
|
|
/// Gets or sets the help file that documents these parameters
|
|
/// </summary>
|
|
public string HelpFile
|
|
{
|
|
get { return _helpFile; }
|
|
set { _helpFile = String.IsNullOrEmpty(value) ? String.Empty : value; }
|
|
}
|
|
private string _helpFile = String.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets or sets private data associated with the runtime-defined parameters.
|
|
/// </summary>
|
|
public object Data { get; set; }
|
|
|
|
internal static RuntimeDefinedParameter[] EmptyParameterArray = new RuntimeDefinedParameter[0];
|
|
} // class RuntimeDefinedParameterDictionary
|
|
} // namespace System.Management.Automation
|