June 26th, 2006

Finding the static methods of a class

PowerShell Team
PowerShell Team

<Edited 7/2/2006 to add categories and tags>

In the previous entry, it showed how you could use the static method GetHostAddresses of the [System.Net.Dns] class to resolve a hostname.  This begs the question, how do you find the static methods of a class.  There are 2 answers to this:

1) SDK documentation.  (remember the trick here – type the name of the class you want and the term “Members” into your search engine).

2) Use Get-Member

Get-Member has a switch -STATIC when directs it to return the static methods and properties of a type.  Here are a couple of examples:

PS> [System.Net.Dns] |Get-Member -Static
   TypeName: System.Net.Dns

Name                  MemberType Definition
—-                  ———- ———-
BeginGetHostAddresses Method     static System.IAsyncResult BeginGetHost…
BeginGetHostByName    Method     static System.IAsyncResult BeginGetHost…
BeginGetHostEntry     Method     static System.IAsyncResult BeginGetHost…
BeginResolve          Method     static System.IAsyncResult BeginResolve…
EndGetHostAddresses   Method     static System.Net.IPAddress[] EndGetHos…
EndGetHostByName      Method     static System.Net.IPHostEntry EndGetHos…
EndGetHostEntry       Method     static System.Net.IPHostEntry EndGetHos…
EndResolve            Method     static System.Net.IPHostEntry EndResolv…
Equals                Method     static System.Boolean Equals(Object obj…
GetHostAddresses      Method     static System.Net.IPAddress[] GetHostAd…
GetHostByAddress      Method     static System.Net.IPHostEntry GetHostBy…
GetHostByName         Method     static System.Net.IPHostEntry GetHostBy…
GetHostEntry          Method     static System.Net.IPHostEntry GetHostEn…
GetHostName           Method     static System.String GetHostName()
ReferenceEquals       Method     static System.Boolean ReferenceEquals(O…
Resolve               Method     static System.Net.IPHostEntry Resolve(S…

PS> [DateTime] |Get-Member -Static
   TypeName: System.DateTime

Name                  MemberType Definition
—-                  ———- ———-
Compare               Method     static System.Int32 Compare(DateTime t1…
DaysInMonth           Method     static System.Int32 DaysInMonth(Int32 y…
Equals                Method     static System.Boolean Equals(DateTime t…
FromBinary            Method     static System.DateTime FromBinary(Int64…
FromFileTime          Method     static System.DateTime FromFileTime(Int…
FromFileTimeUtc       Method     static System.DateTime FromFileTimeUtc(…
FromOADate            Method     static System.DateTime FromOADate(Doubl…
get_Now               Method     static System.DateTime get_Now()
get_Today             Method     static System.DateTime get_Today()
get_UtcNow            Method     static System.DateTime get_UtcNow()
IsLeapYear            Method     static System.Boolean IsLeapYear(Int32 …
op_Addition           Method     static System.DateTime op_Addition(Date…
op_Equality           Method     static System.Boolean op_Equality(DateT…
op_GreaterThan        Method     static System.Boolean op_GreaterThan(Da…
op_GreaterThanOrEqual Method     static System.Boolean op_GreaterThanOrE…
op_Inequality         Method     static System.Boolean op_Inequality(Dat…
op_LessThan           Method     static System.Boolean op_LessThan(DateT…
op_LessThanOrEqual    Method     static System.Boolean op_LessThanOrEqua…
op_Subtraction        Method     static System.DateTime op_Subtraction(D…
Parse                 Method     static System.DateTime Parse(String s),…
ParseExact            Method     static System.DateTime ParseExact(Strin…
ReferenceEquals       Method     static System.Boolean ReferenceEquals(O…
SpecifyKind           Method     static System.DateTime SpecifyKind(Date…
TryParse              Method     static System.Boolean TryParse(String s…
TryParseExact         Method     static System.Boolean TryParseExact(Str…
MaxValue              Property   static System.DateTime MaxValue {get;set;}
MinValue              Property   static System.DateTime MinValue {get;set;}
Now                   Property   System.DateTime Now {get;}
Today                 Property   System.DateTime Today {get;}
UtcNow                Property   System.DateTime UtcNow {get;}

Jeffrey Snover
Windows PowerShell Architect

PSMDTAG:FAQ: How do I find the static methods of a class?
PSMDTAG:DOTNET static methods, System.Net.DNS

Category
PowerShell
Topics
FAQ

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.