Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<!-- the following package(s) are from https://github.com/dotnet/corefx -->
<PackageReference Include="Microsoft.Win32.Registry.AccessControl" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.DirectoryServices" Version="4.5.0" />
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />
<PackageReference Include="System.Management" Version="4.5.0" />
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="4.5.0" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
Expand Down Expand Up @@ -88,8 +91,6 @@
<Compile Remove="engine\ComInterop\VariantArgBuilder.cs" />
<Compile Remove="engine\ComInterop\VariantArray.cs" />
<Compile Remove="engine\ComInterop\VariantBuilder.cs" />
<Compile Remove="engine\ExtraAdapter.cs" />
<Compile Remove="engine\ManagementObjectAdapter.cs" />
<Compile Remove="engine\PSMI\PSNegotiationData.cs" />
<Compile Remove="engine\PSMI\PSPowerShellPipeline.cs" />
<Compile Remove="engine\PSMI\Serialization\InternalMISerializer.cs" />
Expand Down Expand Up @@ -129,6 +130,8 @@
</ItemGroup>

<ItemGroup Condition=" '$(IsWindows)' != 'true' ">
<Compile Remove="engine\ExtraAdapter.cs" />
<Compile Remove="engine\ManagementObjectAdapter.cs" />
<Compile Remove="engine\remoting\commands\ReceivePSSession.cs" />
<Compile Remove="engine\remoting\commands\DisconnectPSSession.cs" />
<Compile Remove="engine\remoting\commands\ConnectPSSession.cs" />
Expand Down
5 changes: 4 additions & 1 deletion src/System.Management.Automation/engine/ExtraAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ internal class DirectoryEntryAdapter : DotNetAdapter

#region member

internal override bool SiteBinderCanOptimize { get { return false; } }
internal override bool CanSiteBinderOptimize(MemberTypes typeToOperateOn)
{
return false;
}

/// <summary>
/// Returns null if memberName is not a member in the adapter or
Expand Down
22 changes: 7 additions & 15 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
using System.Diagnostics.CodeAnalysis;
using Dbg = System.Management.Automation.Diagnostics;
using MethodCacheEntry = System.Management.Automation.DotNetAdapter.MethodCacheEntry;

#if !CORECLR
// System.DirectoryServices are not in CoreCLR
#if !UNIX
using System.DirectoryServices;
using System.Management;
#endif

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
Expand Down Expand Up @@ -2147,15 +2146,7 @@ private static object ConvertNumericThroughDouble(object valueToConvert, Type re
}
}

#if !CORECLR
// No Following Types In CoreCLR
// ManagementObject
// ManagementObjectSearcher
// ManagementClass
// CommaDelimitedStringCollection
// DirectoryEntry
#region Converters_Not_Available_In_CorePS

#if !UNIX
private static ManagementObject ConvertToWMI(object valueToConvert,
Type resultType,
bool recursion,
Expand Down Expand Up @@ -2279,6 +2270,7 @@ private static ManagementClass ConvertToWMIClass(object valueToConvert,
valueToConvert.ToString(), resultType.ToString(), wmiClassException.Message);
}
}
#endif

// System.Configuration.CommaDelimitedStringCollection is derived from the StringCollection class
private static System.Configuration.CommaDelimitedStringCollection ConvertToCommaDelimitedStringCollection(object valueToConvert,
Expand All @@ -2294,6 +2286,7 @@ private static System.Configuration.CommaDelimitedStringCollection ConvertToComm
return commaDelimitedStringCollection;
}

#if !UNIX
private static DirectoryEntry ConvertToADSI(object valueToConvert,
Type resultType,
bool recursion,
Expand Down Expand Up @@ -2351,8 +2344,6 @@ private static DirectorySearcher ConvertToADSISearcher(object valueToConvert,
valueToConvert.ToString(), resultType.ToString(), e.Message);
}
}

#endregion Converters_Not_Available_In_CorePS
#endif

private static StringCollection ConvertToStringCollection(object valueToConvert,
Expand Down Expand Up @@ -4302,7 +4293,8 @@ internal static void RebuildConversionCache()
CacheConversion<bool>(typeofString, typeofBool, LanguagePrimitives.ConvertStringToBool, ConversionRank.Language);
CacheConversion<bool>(typeof(SwitchParameter), typeofBool, LanguagePrimitives.ConvertSwitchParameterToBool, ConversionRank.Language);

#if !CORECLR // No DirectoryService && WMIv1 In CoreCLR
#if !UNIX
// Conversions to WMI and ADSI
CacheConversion<ManagementObjectSearcher>(typeofString, typeof(ManagementObjectSearcher), LanguagePrimitives.ConvertToWMISearcher, ConversionRank.Language);
CacheConversion<ManagementClass>(typeofString, typeof(ManagementClass), LanguagePrimitives.ConvertToWMIClass, ConversionRank.Language);
CacheConversion<ManagementObject>(typeofString, typeof(ManagementObject), LanguagePrimitives.ConvertToWMI, ConversionRank.Language);
Expand Down
10 changes: 4 additions & 6 deletions src/System.Management.Automation/engine/MshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Management.Infrastructure;

#if !CORECLR
#if !UNIX
using System.DirectoryServices;
using System.Management;
#endif

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
Expand Down Expand Up @@ -379,8 +379,7 @@ private void CommonInitialization(object obj)
new PSObject.AdapterSet(new ThirdPartyAdapter(typeof(Microsoft.Management.Infrastructure.CimInstance),
new Microsoft.PowerShell.Cim.CimInstanceAdapter()),
PSObject.dotNetInstanceAdapter);

#if !CORECLR // WMIv1/ADSI Adapters Not Supported in PowerShell Core
#if !UNIX
private static readonly AdapterSet managementObjectAdapter = new AdapterSet(new ManagementObjectAdapter(), dotNetInstanceAdapter);
private static readonly AdapterSet managementClassAdapter = new AdapterSet(new ManagementClassApdapter(), dotNetInstanceAdapter);
private static readonly AdapterSet directoryEntryAdapter = new AdapterSet(new DirectoryEntryAdapter(), dotNetInstanceAdapter);
Expand Down Expand Up @@ -410,8 +409,7 @@ private static AdapterSet MappedInternalAdapterSet(object obj)
if (obj is PSMemberSet) { return PSObject.s_mshMemberSetAdapter; }
if (obj is PSObject) { return PSObject.s_mshObjectAdapter; }
if (obj is CimInstance) { return PSObject.s_cimInstanceAdapter; }

#if !CORECLR // WMIv1/ADSI Adapters Not Supported in PowerShell Core
#if !UNIX
if (obj is ManagementClass) { return PSObject.managementClassAdapter; }
if (obj is ManagementBaseObject) { return PSObject.managementObjectAdapter; }
if (obj is DirectoryEntry) { return PSObject.directoryEntryAdapter; }
Expand Down
14 changes: 6 additions & 8 deletions src/System.Management.Automation/engine/parser/TypeResolver.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Management.Infrastructure;
using Microsoft.PowerShell.Commands;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
#if !UNIX
using System.DirectoryServices;
#endif
using System.Globalization;
using System.Linq;
using System.Management.Automation.Language;
Expand All @@ -18,12 +23,6 @@
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Xml;
using Microsoft.Management.Infrastructure;
using Microsoft.PowerShell.Commands;
#if !CORECLR
// System.DirectoryServices are not in CoreCLR
using System.DirectoryServices;
#endif

namespace System.Management.Automation.Language
{
Expand Down Expand Up @@ -793,8 +792,7 @@ internal static class CoreTypes
{ typeof(CimSession), new[] { "CimSession" } },
{ typeof(MailAddress), new[] { "mailaddress" } },
{ typeof(SemanticVersion), new[] { "semver" } },
#if !CORECLR
// Following types not in CoreCLR
#if !UNIX
{ typeof(DirectoryEntry), new[] { "adsi" } },
{ typeof(DirectorySearcher), new[] { "adsisearcher" } },
{ typeof(ManagementClass), new[] { "wmiclass" } },
Expand Down
6 changes: 3 additions & 3 deletions test/powershell/Language/Parser/TypeAccelerator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ Describe "Type accelerators" -Tags "CI" {
}
)

if ( $IsCoreCLR )
if ( !$IsWindows )
{
$totalAccelerators = 91
}
else
{
$totalAccelerators = 95
$totalAccelerators = 96

$extraFullPSAcceleratorTestCases = @(
@{
Expand Down Expand Up @@ -418,7 +418,7 @@ Describe "Type accelerators" -Tags "CI" {
$TypeAcceleratorsType::Get[$Accelerator] | Should -Be ($Type)
}

It 'Should have a type accelerator for non-dotnet-core type: <Accelerator>' -Skip:$IsCoreCLR -TestCases $extraFullPSAcceleratorTestCases {
It 'Should have a type accelerator for non-dotnet-core type: <Accelerator>' -Skip:(!$IsWindows) -TestCases $extraFullPSAcceleratorTestCases {
param($Accelerator, $Type)
$TypeAcceleratorsType::Get[$Accelerator] | Should -Be ($Type)
}
Expand Down