You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Move sub-function ToPascalCase to utility class
Move the ToPascalCase outside of the ConvertTo-FunctionDefinition
function and into a shared utility class for reuse.
* Refactor Expand-MemberExpression
This change refactors Expand-MemberExpression significantly.
- Breaking Change - Remove TemplateName and NoParameterNameComments
parameters
- Remove the overly complicated logic for targeting a specific overload
and replace it with a QuickOpen choice prompt
- Change expression generation to use StringBuilder instead of
PSStringTemplate. This is the first step in removing the dependancy.
- Improve logic for determining the Type.Get* overload required to
resolve a non-public member
- Fix a variety of scenarios where invalid expressions would be
generated
- Add ShowOnThrow parameter to internal function GetAncestorOrThrow
- Fix an issue where detection of shortest resolvable type name would
use the TypeResolutionScope, resulting in invalid type expressions
* Update help to reflect changes
The Expand-MemberExpression function creates an expression for the closest MemberExpressionAst to the cursor in the current editor context. This is mainly to assist with creating expressions to access private members of .NET classes through reflection.
55
+
The Expand-MemberExpression function expands member expressions to a more explicit statement.
The Expand-MemberExpression function creates an expression for the closest MemberExpressionAst to the cursor in the current editor context. This is mainly to assist with creating expressions to access private members of .NET classes through reflection.
21
+
The Expand-MemberExpression function expands member expressions to a more explicit statement. This
22
+
function has two main purposes.
22
23
23
-
The expression is created using string templates. There are templates for several ways of accessing members including InvokeMember, GetProperty/GetValue, and a more verbose GetMethod/Invoke. If using the GetMethod/Invoke template it will automatically build type expressions for the "types" argument including nonpublic and generic types. If a template is not specified, this function will attempt to determine the most fitting template. If you have issues invoking a method with the default, try the VerboseInvokeMethod template. This function currently works on member expressions attached to the following:
24
+
* Add parameter name comments (e.g. <# parameterName: #>) to method invocation arguments
24
25
25
-
1. Type literal expressions (including invalid expressions with non public types)
26
+
* Invokable expressions that target non-public class members using reflection
26
27
27
-
2. Variable expressions where the variable exists within a currently existing scope.
28
+
As an editor command, this function will expand the AST closest to the current cursor location
29
+
if applicable.
28
30
29
-
3. Any other scenario where standard completion works.
31
+
## EXAMPLES
30
32
31
-
4. Any number of nested member expressions where one of the above is true at some point in the chain.
33
+
### -------------------------- EXAMPLE 1 --------------------------
A template is automatically chosen based on member type and visibility. You can use this parameter to force the use of a specific template.
75
-
76
-
```yaml
77
-
Type: String
78
-
Parameter Sets: (All)
79
-
Aliases:
80
-
81
-
Required: False
82
-
Position: Named
83
-
Default value: None
84
-
Accept pipeline input: False
85
-
Accept wildcard characters: False
86
-
```
87
-
88
-
### -NoParameterNameComments
89
-
90
-
By default expanded methods will have a comment with the parameter name on each line. (e.g. `<# paramName: #> $paramName,`) If you specify this parameter it will be omitted.
91
-
92
-
```yaml
93
-
Type: SwitchParameter
94
-
Parameter Sets: (All)
95
-
Aliases:
96
-
97
-
Required: False
98
-
Position: Named
99
-
Default value: False
100
-
Accept pipeline input: False
101
-
Accept wildcard characters: False
102
-
```
103
-
104
143
### CommonParameters
105
144
106
145
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
@@ -115,5 +154,16 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
115
154
116
155
## NOTES
117
156
118
-
## RELATED LINKS
157
+
* When this function is building reflection statements, it will automatically choose the simpliest form
158
+
of the Type.Get* methods that will resolve the target member.
159
+
160
+
* Member resolution is currently only possible in the following scenarios:
161
+
* Type literal expressions, including invalid expressions with non public types like [localpipeline]
162
+
* Variable expressions where the variable exists within a currently existing scope
163
+
* Any other scenario where standard completion works
164
+
* Any number of nested member expressions where one of the above is true at some point in the chain
119
165
166
+
* Member resolution may break in member chains if a member returns a type that is too generic like
0 commit comments