/// <summary> /// This method is to get the unique key for a UsingExpressionAst. The key is a base64 /// encoded string based on the text of the UsingExpressionAst. /// /// This method is used when handling a script block that contains $using for Invoke-Command. /// /// When run Invoke-Command targeting a machine that runs PSv3 or above, we pass a dictionary /// to the remote end that contains the key of each UsingExpressionAst and its value. This method /// is used to generate the key. /// </summary> /// <param name="usingAst">A using expression</param> /// <returns>Base64 encoded string as the key of the UsingExpressionAst</returns> internal static string GetUsingExpressionKey(Language.UsingExpressionAst usingAst) { Diagnostics.Assert(usingAst != null, "Caller makes sure the parameter is not null"); // We cannot call ToLowerInvariant unconditionally, because usingAst might // contain IndexExpressionAst in its SubExpression, such as // $using:bar["AAAA"] // and the index "AAAA" might not get us the same value as "aaaa". // // But we do want a unique key to represent the same UsingExpressionAst's as much // as possible, so as to avoid sending redundant key-value's to remote machine. // As a workaround, we call ToLowerInvariant when the SubExpression of usingAst // is a VariableExpressionAst, because: // (1) Variable name is case insensitive; // (2) People use $using to refer to a variable most of the time. string usingAstText = usingAst.ToString(); if (usingAst.SubExpression is Language.VariableExpressionAst) { usingAstText = usingAstText.ToLowerInvariant(); } return(StringToBase64Converter.StringToBase64String(usingAstText)); }
public static VariableExpressionAst ExtractUsingVariable(UsingExpressionAst usingExpressionAst) { throw new NotImplementedException(usingExpressionAst.ToString()); }
public static VariableExpressionAst ExtractUsingVariable(UsingExpressionAst usingExpressionAst) { throw new NotImplementedException(usingExpressionAst.ToString()); }