Skip to content
Closed
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
10 changes: 10 additions & 0 deletions src/System.Management.Automation/engine/TypeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Xml;
using Dbg = System.Diagnostics.Debug;
using System.Security.Permissions;
using Microsoft.PowerShell.Commands;

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings

Expand Down Expand Up @@ -4399,6 +4400,15 @@ private bool ProcessIsBuiltIn(string filePath, ConcurrentBag<string> errors, out
else if (string.Equals(Path.Combine(psHome, "typesv3.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase))
{
ProcessTypeData(filePath, errors, TypesV3_Ps1Xml.Get());

var providerItemTypeData = new[]
{
FileSystemProviderProperties.GetCodePropertiesTypeData(),
RegistryProviderProperties.GetCodePropertiesTypeData()
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this in TypesV3_Ps1Xml class?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure - I just hacked it in to get it in the same timing scope as the rest of the types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, there is no longer a good reason to keep TypesV3_Ps1Xml separate from Types_PS1Xml.

The original idea was to make it easy to compare with the ps1xml files from V5, but they've diverged enough at this point that it doesn't matter.


ProcessTypeData(filePath, errors, providerItemTypeData);

result = true;
}
else if (string.Equals(Path.Combine(psHome, "GetEvent.types.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Provider;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.XPath;
using Microsoft.Win32.SafeHandles;

using Dbg = System.Management.Automation;
using System.Runtime.InteropServices;
using System.Management.Automation.Runspaces;

namespace Microsoft.PowerShell.Commands
{
Expand Down Expand Up @@ -166,6 +169,19 @@ internal override bool IsFilterSet()
return (attributeFilterSet || base.IsFilterSet());
}

/// <inheritdoc />
protected override bool TrySetCodeProperties(object item, string path)
{
if (PSObject.Base(item) is FileSystemInfo fileSystemInfo)

@iSazonov Ilya (iSazonov) Aug 13, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we enhance and use public enum ProviderCapabilities

@powercode Staffan Gustafsson (powercode) Aug 13, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea!

{
var fileSystemProviderProperties = new FileSystemProviderProperties(this, path, PSDriveInfo);
FileSystemProviderProperties.AttachObjectProperties(fileSystemInfo, fileSystemProviderProperties);
return true;
}

return false;
}

/// <summary>
/// Gets the dynamic parameters for get-childnames on the
/// FileSystemProvider.
Expand Down Expand Up @@ -366,6 +382,7 @@ protected override ProviderInfo Start(ProviderInfo providerInfo)
s_tracer.WriteLine("Not setting home directory {0} - does not exist", homeDirectory);
}
}

return providerInfo;
} // Start

Expand Down Expand Up @@ -8152,6 +8169,52 @@ private static SafeFileHandle WinOpenReparsePoint(string reparsePoint, FileDesir
}

#endregion

/// <summary>
/// Provides storage for the common provider properties in a more efficient
/// way than PSNoteProperty.
/// </summary>
public class FileSystemProviderProperties : NavigationProviderPropertiesBase<FileSystemProviderProperties>
{
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemProviderProperties"/> class.
/// </summary>
/// <param name="provider">The FileSystemProvider that provided the path.</param>
/// <param name="path">The path to store properties for.</param>
/// <param name="driveInfo">The drive that the path belongs to.</param>
public FileSystemProviderProperties(FileSystemProvider provider, string path, PSDriveInfo driveInfo)
: base(path, driveInfo, provider)
{
}

/// <summary>
/// Code property for PSIsContainer.
/// </summary>
/// <param name="obj">The extended object.</param>
/// <returns>The PSIsContainer for the extended object.</returns>
public static bool GetIsContainer(PSObject obj) => obj.BaseObject is DirectoryInfo;

internal static TypeData GetCodePropertiesTypeData()
{
var td = new TypeData(typeof(FileSystemInfo));
var typeMembers = td.Members;

void AddCodeProperty(string name, string memberName)
{
var methodInfo = typeof(FileSystemProviderProperties).GetMethod(memberName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
typeMembers.Add(name, new CodePropertyData(name, methodInfo, null));
}

AddCodeProperty("PSChildName", nameof(GetChildName));
AddCodeProperty("PSDrive", nameof(GetPSDrive));
AddCodeProperty("PSIsContainer", nameof(GetIsContainer));
AddCodeProperty("PSParentPath", nameof(GetParentPath));
AddCodeProperty("PSPath", nameof(GetPath));
AddCodeProperty("PSProvider", nameof(GetProviderInfo));

return td;
}
}
}

namespace System.Management.Automation.Internal
Expand Down
Loading