2016-04-11 17 views
0

IArgumentCompleter'dan devralınan C# 'da özel bir argüman tamamlayıcısı uyguluyorum. CompleteArgument yılında ben Geçerli dosya sistemi konumunu IArgumentCompleter bir C# uygulamasında nasıl edinebilirim?

Runspace.DefaultRunspace.SessionStateProxy.Path.CurrentFileSystemLocation.Path 

çalıştı ama o bir boru hattı zaten çalışıyor bana bir istisna atar

$ExecutionContext.SessionState.Path.CurrentFileSystemLocation.ProviderPath 

eşdeğer yapmaya çalışıyoruz.

Bunu yapmanın doğru yolu nedir?

+1

'EngineIntrinsics ei; kullanarak (PowerShell ps = PowerShell.Create (RunspaceMode.CurrentRunspace)) {ei = ps.AddScript ("$ ExecutionContext"). () [0]} 'işlevini çağırır. – PetSerAl

cevap

0

@PetSerAl gelen açıklama bir cevaptır:

string pwd; 
EngineIntrinsics ei; 
using(PowerShell ps = PowerShell.Create(RunspaceMode.CurrentRunspace)) 
{ 
    ei = ps.AddScript("$ExecutionContext").Invoke<EngineIntrinsics>()[0] 
    pwd = ei.SessionState.Path.CurrentFileSystemLocation.ProviderPath 
} 
İlgili konular