Welcome to MSDN Blogs Sign in | Join | Help

Finding the static methods of a class

<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

Published Monday, June 26, 2006 1:52 PM by PowerShellTeam
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# PowerShell - Finding the static methods of a class

Jeffrey Snover posted a great post on the PowerShell Blog
In the previous entry, it showed how you could...
Monday, June 26, 2006 10:16 AM by Ron Crumbaker at myITforum.com, Inc.

# Interesting Finds: June 26, 2005 AM edition

Monday, June 26, 2006 10:19 AM by Jason Haley

# re: Finding the static methods of a class

Supplying input object through "-InputObject" results in returning static members of "String" type though.(Get-Member -InputObject [System.Net.Dns] -Static)

If i don't pass the type name to get-member as a pipeline input, how does "Get-Member" handle "[System.Net.Dns]"?

Thank you in advance.
Monday, June 26, 2006 12:36 PM by dontBotherMeWithSpam

# re: Finding the static methods of a class

Put the type in parans and it will work for you:

Get-Member -InputObject ([System.Net.Dns]) -Static

The parans say EXECUTE THIS which then produces the TYPE object which is then passed to the parameter.

Jeffrey Snover
Windows PowerShell Architect
Monday, June 26, 2006 5:38 PM by PowerShellTeam

# re: Finding the static methods of a class

Hello, I hope you see this comment, but I am curious to know how to enumerate WMI static methods. The root\cimv2:Win32_Product class contains several static methods, and I tried using this command to locate them through Powershell: Get-WmiObject Win32_Product | Get-Member -Static It appears to only work on .NET static members ... can this be fixed in the final release, or am I missing something? Thanks
Friday, October 06, 2006 12:13 PM by Trevor Sullivan

# re: Finding the static methods of a class

Interesting post, haven't used it yet but after reading this will give it a try. Thanks.

Wednesday, October 15, 2008 5:07 PM by Computer Forum

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker