本文整理汇总了C#中System.Management.Automation.Provider.CmdletProvider.GetDriveFromProviderInfo方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProvider.GetDriveFromProviderInfo方法的具体用法?C# CmdletProvider.GetDriveFromProviderInfo怎么用?C# CmdletProvider.GetDriveFromProviderInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.Provider.CmdletProvider
的用法示例。
在下文中一共展示了CmdletProvider.GetDriveFromProviderInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDefaultDrives
private void AddDefaultDrives(CmdletProvider providerInstance, ProviderRuntime runtime)
{
DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;
if (driveProvider == null)
{
return;
}
var drives = driveProvider.InitializeDefaultDrives(runtime);
if (drives == null)
{
throw new PSInvalidOperationException("The default drive collection for this null!");
}
if (drives.Count == 0)
{
drives = providerInstance.GetDriveFromProviderInfo();
}
foreach (PSDriveInfo driveInfo in drives)
{
if (driveInfo == null)
{
continue;
}
try
{
// always to global scope
// use NewSkipInit because the dafault drives are inited
_sessionState.RootSessionState.Drive.NewSkipInit(driveInfo,
SessionStateScope<PSDriveInfo>.ScopeSpecifiers.Global.ToString());
}
catch
{
// TODO: What should we do if the drive name is not unique?
// => I guess overwrite the old one and write a warning (however this works from here)
}
}
}