Type signatures are a custom query language built into PowerShell type expressions to enable complex searches of the environment. Originally built to more easily search for generic types, but allows for very precise exploration of currently loaded assemblies.
assignable
exact
contains
any
ref
out
in
anyof
allof
not
class
struct
record
readonlystruct
readonlyrefstruct
refstruct
enum
referencetype
- Pointers
- Generic Parameters (
T
,TT
, andTM
) primitive
interface
abstract
concrete
index
number
hasdefault
decoration
,hasattr
generic
- Resolution Maps
By default all type expressions are implicitly interpreted as assignable. Meaning if you enter [IO.FileSystemInfo]
then it will also match [IO.FileInfo]
and [IO.DirectoryInfo]
.
Find-Member -ParameterType { [IO.FileSystemInfo] }
# You can also be explicit about assignable:
Find-Member -ParameterType { [assignable[IO.FileSystemInfo]] } |
|
Signature |
|
---|---|
✔️ |
void Example(FileInfo file); |
✔️ |
void Example(FileSystemInfo fso); |
❌ |
void Example(object obj); |
Sometimes you may want to only match a specific type and not any of it's subclasses or implementees.
Find-Member -ParameterType { [exact[IO.FileSystemInfo]] } |
|
Signature |
|
---|---|
✔️ |
void Example(FileSystemInfo fso); |
❌ |
void Example(FileInfo file); |
Recurses a type's elements and generic arguments for a match.
Find-Member -ParameterType { [contains[int]] } |
|
Signature |
|
---|---|
✔️ |
void Example(int value); |
✔️ |
void Example(IList<int[]> values); |
❌ |
void Example(IList<long> values); |
Find-Member -ParameterType { [contains[exact[IO.FileSystemInfo]]] } |
|
Signature |
|
---|---|
✔️ |
void Example(IList<FileSystemInfo> fsos); |
❌ |
void Example(IList<FileInfo> files); |
Matches anything. It's main purpose is as a stand in for generic arguments e.g. [Span[any]]
to match any type of Span<>
.
Find-Member -ParameterType { [Span[any]] } |
|
Signature |
|
---|---|
✔️ |
void Example(Span<int> values); |
✔️ |
void Example(Span<DateTime> dates); |
❌ |
void Example(ReadOnlySpan<int> values); |
Find-Member -ParameterType { [any] } |
|
Signature |
|
---|---|
✔️ |
all the things |
An argument passed by ref
, excludes out
and in
.
Find-Member -ParameterType { [ref] [any] }
Find-Member -ParameterType { [ref[any]] } |
|
Signature |
|
---|---|
✔️ |
void Example(ref int value); |
✔️ |
void Example(ref string value); |
❌ |
void Example(out long value); |
Find-Member -ParameterType { [ref] [DateTime] } |
|
Signature |
|
---|---|
✔️ |
void Example(ref DateTime date); |
❌ |
void Example(in DateTime date); |
❌ |
void Example(out int value); |
An argument passed by out
, excludes standard ref
and in
.
Find-Member -ParameterType { [out] [any] }
Find-Member -ParameterType { [out[any]] } |
|
Signature |
|
---|---|
✔️ |
void Example(out int value); |
✔️ |
void Example(out string value); |
❌ |
void Example(ref long value); |
Find-Member -ParameterType { [out] [DateTime] } |
|
Signature |
|
---|---|
✔️ |
void Example(out DateTime date); |
❌ |
void Example(in DateTime date); |
❌ |
void Example(ref int value); |
An argument passed by in
, excludes standard ref
and out
.
Find-Member -ParameterType { [in] [any] }
Find-Member -ParameterType { [in[any]] } |
|
Signature |
|
---|---|
✔️ |
void Example(out int value); |
✔️ |
void Example(out string value); |
❌ |
void Example(ref long value); |
Find-Member -ReturnType { [in] [any] } |
|
Signature |
|
---|---|
✔️ |
ref readonly int Example(); |
✔️ |
ref readonly string Example(); |
❌ |
ref int Example(); |
Return true if any of it's arguments match.
Find-Member -ParameterType { [anyof[int, double]] } |
|
Signature |
|
---|---|
✔️ |
void Example(int value); |
✔️ |
void Example(double value); |
❌ |
void Example(long value); |
Find-Member -ParameterType { [anyof[bool, contains[int]]] } |
|
Signature |
|
---|---|
✔️ |
void Example(bool value); |
✔️ |
void Example(IList<int> values); |
❌ |
void Example(long value); |
Return true if all of it's arguments match.
Find-Member -ParameterType { [allof[primitive, [not[anyof[bool, char]]]]] } |
|
Signature |
|
---|---|
✔️ |
void Example(int value); |
✔️ |
void Example(long value); |
❌ |
void Example(bool value); |
❌ |
void Example(object obj); |
Returns true if it's argument does not match.
Find-Member -ParameterType { [not[int]] } |
|
Signature |
|
---|---|
✔️ |
void Example(bool value); |
❌ |
void Example(int value); |
Find-Member -ParameterType { [not[contains[int]]] } |
|
Signature |
|
---|---|
✔️ |
void Example(IList<bool> values); |
❌ |
void Example(IList<int> values); |
❌ |
void Example(int value); |
Only match concrete classes (not an interface or ValueType
).
Find-Member -ParameterType { [class] } |
|
Signature |
|
---|---|
✔️ |
void Example(object value); |
❌ |
void Example(int value); |
Find-Member -ParameterType { [Collections.Generic.List[class]] } |
|
Signature |
|
---|---|
✔️ |
void Example(List<string> values); |
❌ |
void Example(List<int> values); |
❌ |
void Example(List<IDisposable> values); |
Only match ValueType
types that are not exactly ValueType
or Enum
.
Find-Member -ParameterType { [struct] } |
|
Signature |
|
---|---|
✔️ |
void Example(int value); |
✔️ |
void Example(DateTime date); |
❌ |
void Example(object obj); |
❌ |
void Example(Enum value); |
❌ |
void Example(ValueType value); |
Find-Member -ParameterType { [Collections.Generic.List[class]] } |
|
Signature |
|
---|---|
✔️ |
void Example(List<string> values); |
❌ |
void Example(List<int> values); |
❌ |
void Example(List<DateTime> values); |
Only match types defined with the record
keyword in C#.
Find-Member -ParameterType { [record] } |
|
Signature |
|
---|---|
✔️ |
public record Person(string Name);
void Example(Person person); |
❌ |
void Example(object obj); |
Only match structs defined with the readonly
keyword in C#.
Find-Member -ParameterType { [readonlystruct] } |
|
Signature |
|
---|---|
✔️ |
public readonly struct Person
{
public readonly string Name;
}
void Example(Person person); |
❌ |
void Example(object obj); |
Only match structs defined with the readonly
and ref
keywords in C#.
Find-Member -ParameterType { [readonlyrefstruct] } |
|
Signature |
|
---|---|
✔️ |
public readonly ref struct Person
{
public readonly ReadOnlySpan<char> Name;
}
void Example(Person person); |
❌ |
void Example(object obj); |
Only match structs defined with the ref
keyword in C#.
Find-Member -ParameterType { [refstruct] } |
|
Signature |
|
---|---|
✔️ |
public ref struct Person
{
public ReadOnlySpan<char> Name;
}
void Example(Person person); |
❌ |
void Example(object obj); |
Only concrete Enum
types.
Find-Member -ParameterType { [enum] } |
|
Signature |
|
---|---|
✔️ |
void Example(BindingFlags flags); |
❌ |
void Example(Enum value); |
❌ |
void Example(object value); |
Any reference type including classes, interfaces, and boxed value types.
Find-Member -ParameterType { [referencetype] } |
|
Signature |
|
---|---|
✔️ |
void Example(object value); |
✔️ |
void Example(Enum value); |
❌ |
void Example(int value); |
References raw pointer types replacing C#'s *
symbol with +
.
Find-Member -ParameterType { [void++] } |
|
Signature |
|
---|---|
✔️ |
void Example(void** ptr); |
❌ |
void Example(void* ptr); |
❌ |
void Example(int* ptr); |
❌ |
void Example(object value); |
Find-Member -ReturnType { [pointer[any, a1..]] } |
|
Signature |
|
---|---|
✔️ |
void** Example(); |
✔️ |
int* Example(); |
❌ |
void Example(); |
❌ |
object Example(); |
Find-Member -ReturnType { [pointer[any, a2..3]] } |
|
Signature |
|
---|---|
✔️ |
void** Example(); |
❌ |
int* Example(); |
✔️ |
void*** Example(); |
❌ |
void**** Example(); |
References a generic parameter. T
matches any kind, TT
matches generic type parameters and TM
matches generic method parameters. Optionally add a number to indicate generic parameter position (e.g. T0
). Add generic arguments to indicate required generic constraints (e.g. [T[unmanaged]]
).
Find-Member -ParameterType { [T] } |
|
Signature |
|
---|---|
✔️ |
void Example(T value); |
Find-Member -ParameterType { [TM] } |
|
Signature |
|
---|---|
✔️ |
void Example<TM>(TM value); |
❌ |
void Example(T value); |
Find-Member -ParameterType { [TM0] } |
|
Signature |
|
---|---|
✔️ |
void Example<TM>(TM value); |
❌ |
TM0 Example<TM0, TM1>(TM0 value); |
Find-Member -ParameterType { [T[unmanaged]] } |
|
Signature |
|
---|---|
✔️ |
public class MyClass<T> where T : unmanaged
{ }
void Example(T value); |
Find-Member -ParameterType { [T[new]] } |
|
Signature |
|
---|---|
✔️ |
public class MyClass<T> where T : new()
{ }
void Example(T value); |
Find-Member -ParameterType { [T[Collections.IList]] } |
|
Signature |
|
---|---|
✔️ |
public class MyClass<T> where T : IList
{ }
void Example(T value); |
Find-Member -ParameterType { [T[struct]] } |
|
Signature |
|
---|---|
✔️ |
public class MyClass<T> where T : struct
{ }
void Example(T value); |
Find-Member -ParameterType { [T[class]] } |
|
Signature |
|
---|---|
✔️ |
public class MyClass<T> where T : class
{ }
void Example(T value); |
Matches bool, byte, char, double, short, int, long, IntPtr, sbyte, float, ushort, uint, ulong, or UIntPtr.
Find-Member -ParameterType { [primitive] } |
|
Signature |
|
---|---|
✔️ |
void Example(char value); |
✔️ |
void Example(float value); |
❌ |
void Example(string value); |
Matches only interfaces, does not match concrete types.
Find-Member -ParameterType { [interface] } |
|
Signature |
|
---|---|
✔️ |
void Example(IDisposable disposable); |
❌ |
void Example(object obj); |
❌ |
void Example(int value); |
Matches only abstract types.
Find-Member -ParameterType { [abstract] } |
|
Signature |
|
---|---|
❌ |
void Example(IDisposable disposable); |
❌ |
void Example(object obj); |
❌ |
void Example(int value); |
❌ |
void Example(T value); |
✔️ |
void Example(FileSystemInfo value); |
✔️ |
void Example(FileInfo value); |
Matches only concrete types. No abstract classes, interfaces, or generic parameters.
Find-Member -ParameterType { [abstract] } |
|
Signature |
|
---|---|
❌ |
void Example(IDisposable disposable); |
✔️ |
void Example(object obj); |
✔️ |
void Example(int value); |
❌ |
void Example(T value); |
❌ |
void Example(FileSystemInfo value); |
✔️ |
void Example(FileInfo value); |
Matches only parameters in at a specific index in the method.
Find-Member -ParameterType { [allof[index0, string]] } |
|
Signature |
|
---|---|
❌ |
void Example(IDisposable disposable); |
✔️ |
void Example(string str); |
❌ |
void Example(int value, string str); |
Find-Member -ParameterType { [allof[index1.., string]] } |
|
Signature |
|
---|---|
❌ |
void Example(IDisposable disposable); |
❌ |
void Example(string str); |
✔️ |
void Example(int value, string str); |
✔️ |
void Example(int value, object obj, string str); |
✔️ |
void Example(string value, object obj, string str); |
# You can also use `i`
Find-Member -ParameterType { [allof[i0..1, string]] } |
|
Signature |
|
---|---|
❌ |
void Example(IDisposable disposable); |
✔️ |
void Example(string str); |
✔️ |
void Example(int value, string str); |
❌ |
void Example(int value, object obj, string str); |
✔️ |
void Example(string value, object obj, string str); |
Matches a hard coded list of types representing numbers.
Find-Type -Signature { [number] } |
|
Signature |
|
---|---|
✔️ |
public readonly struct SByte |
✔️ |
public readonly struct Byte |
✔️ |
public readonly struct Int16 |
✔️ |
public readonly struct UInt16 |
✔️ |
public readonly struct Int32 |
✔️ |
public readonly struct UInt32 |
✔️ |
public readonly struct Int64 |
✔️ |
public readonly struct UInt64 |
✔️ |
public readonly struct Single |
✔️ |
public readonly struct Double |
✔️ |
public readonly struct Half |
✔️ |
public readonly struct IntPtr |
✔️ |
public readonly struct UIntPtr |
✔️ |
public readonly struct BigInteger |
❌ |
public class Object |
❌ |
public readonly struct DateTime |
Matches only parameters with a default value.
Find-Member -ParameterType { [hasdefault] } |
|
Signature |
|
---|---|
❌ |
void Example(string str); |
✔️ |
void Example(string str = "something"); |
✔️ |
void Example(CancellationToken token = default); |
Matches parameters or types decorated with this attribute.
Find-Member -ParameterType { [hasattr[ParamArrayAttribute]] } |
|
Signature |
|
---|---|
✔️ |
void Example(params object[] args); |
❌ |
void Example(object[] args); |
Find-Member -ParameterType {
[hasattr[Management.Automation.CmdletAttribute]]
} |
|
Signature |
|
---|---|
✔️ |
void Example(OutStringCommand command); |
Provides a way to specify a signature that takes arguments for a generic type definition.
Find-Member -ParameterType {
[generic[exact[Collections.Generic.IList`1], args[struct]]]
} |
|
Signature |
|
---|---|
✔️ |
void Example(IList<DateTime> values); |
❌ |
void Example(List<DateTime> values); |
❌ |
void Example(IList<object> values); |
You can provide a hashtable of name
to Signature
/Type
to the -ResolutionMap
parameter to create your own keywords or override type resolution.
$map = @{
number = {
[anyof[bigint, [allof[primitive, [not[anyof[bool, char]]]]]]]
}
anymemory = {
[anyof[Span[any], ReadOnlySpan[any], Memory[any], ReadOnlyMemory[any]]]
}
LocalRunspace = (Find-Type LocalRunspace -Force)
}
Find-Type -Force -ResolutionMap $map -Signature {
[anyof[number, anymemory, LocalRunspace]]
} |
|
Signature |
|
---|---|
✔️ |
public struct Byte { } |
✔️ |
public struct Double { } |
✔️ |
public struct Int16 { } |
✔️ |
public struct Int32 { } |
✔️ |
public struct Int64 { } |
✔️ |
public struct IntPtr { } |
✔️ |
public struct Memory<T> { } |
✔️ |
public struct ReadOnlyMemory<T> { } |
✔️ |
public struct ReadOnlySpan<T> { } |
✔️ |
public struct SByte { } |
✔️ |
public struct Single { } |
✔️ |
public struct Span<T> { } |
✔️ |
public struct UInt16 { } |
✔️ |
public struct UInt32 { } |
✔️ |
public struct UInt64 { } |
✔️ |
public struct UIntPtr { } |
✔️ |
private class LocalRunspace { } |
✔️ |
public struct BigInteger { } |