Skip to content

Commit 94c1a30

Browse files
committed
Document runspace extension method
1 parent 8695d53 commit 94c1a30

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/PowerShellEditorServices/Services/PowerShell/Utility/RunspaceExtensions.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ internal static class RunspaceExtensions
1818
static RunspaceExtensions()
1919
{
2020
// PowerShell ApartmentState APIs aren't available in PSStandard, so we need to use reflection.
21-
if (!VersionUtils.IsNetCore || VersionUtils.IsPS7OrGreater)
22-
{
23-
MethodInfo setterInfo = typeof(Runspace).GetProperty("ApartmentState").GetSetMethod();
24-
Delegate setter = Delegate.CreateDelegate(typeof(Action<Runspace, ApartmentState>), firstArgument: null, method: setterInfo);
25-
s_runspaceApartmentStateSetter = (Action<Runspace, ApartmentState>)setter;
26-
}
21+
MethodInfo setterInfo = typeof(Runspace).GetProperty("ApartmentState").GetSetMethod();
22+
Delegate setter = Delegate.CreateDelegate(typeof(Action<Runspace, ApartmentState>), firstArgument: null, method: setterInfo);
23+
s_runspaceApartmentStateSetter = (Action<Runspace, ApartmentState>)setter;
2724

2825
MethodInfo getRemotePromptMethod = typeof(HostUtilities).GetMethod("GetRemotePrompt", BindingFlags.NonPublic | BindingFlags.Static);
2926
ParameterExpression runspaceParam = Expression.Parameter(typeof(Runspace));
@@ -45,6 +42,13 @@ public static void SetApartmentStateToSta(this Runspace runspace)
4542
s_runspaceApartmentStateSetter?.Invoke(runspace, ApartmentState.STA);
4643
}
4744

45+
/// <summary>
46+
/// Augment a given prompt string with a remote decoration.
47+
/// This is an internal method on <c>Runspace</c> in PowerShell that we reuse via reflection.
48+
/// </summary>
49+
/// <param name="runspace">The runspace the prompt is for.</param>
50+
/// <param name="basePrompt">The base prompt to decorate.</param>
51+
/// <returns>A prompt string decorated with remote connection details.</returns>
4852
public static string GetRemotePrompt(this Runspace runspace, string basePrompt)
4953
{
5054
return s_getRemotePromptFunc(runspace, basePrompt);

0 commit comments

Comments
 (0)