Freigeben über


Getting MSDN help urls for .NET BCL types and Members

 Often when playing with .Net objects in Monad, I need to use MSDN class library reference to learn how to use a particular type and its members. Now, I have my bookmarks and favorite search engine but I always thought it would be cool if get-member cmdlet could provide me a help link/reference to go to. Thanks to the way MSDN organizes the class library content this seems possible.  MSDN uses the .Net namespace to organize the content. So https://msdn2.microsoft.com/library/System.Diagnostics.Process.aspx  refers to the page providing information on the Process Type while https://msdn2.microsoft.com/library/System.Diagnostics.Process.Start.aspx refers to the page providing information on the Start method.

Using monad's Extended Type System (ETS) features and the way MSDN orgranizes the information I can achieve what  I want.  The get-member cmdlet outputs an object of Type System.Management.Automation.Commands.MemberDefinition. I will extend this type by adding a ScriptProperty called HelpLink via types.mshxml.  The following is the xml snippet that I add to my types.mshxml. The ScriptBlock basically constructs a url string based on the type name and name of the member being accessed. You will have to restart msh to get the changes in.

<Type>
<Name>System.Management.Automation.Commands.MemberDefinition</Name>
<Members>
<ScriptProperty>
<Name>HelpLink</Name>
<GetScriptBlock> "https://msdn2.microsoft.com/library/" + $this.typename +"." +$this.name+".aspx"</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>

 This is what the get-member output looks like before adding the extension.

MSH> $a = ps msh

MSH > $a | get-member -membertype method -name Start | format-list

TypeName : System.Diagnostics.Process
Name : Start
MemberType : Method
Definition : System.Boolean Start()

This is what the get-member output looks like after the extension.

MSH C:\> $a | get-member -membertype method -name Start | format-list

HelpLink : https://msdn2.microsoft.com/library/System.Diagnostics.Process.Start.aspx
TypeName : System.Diagnostics.Process
Name : Start
MemberType : Method
Definition : System.Boolean Start()

I can now navigate to the exact help link directly from monad whenever needed :-). This seems to work ok for types in the base class library, but will not work for COM objects or the adapted objects or any custom types you might have.

-Abhishek Agrawal

Comments

  • Anonymous
    December 30, 2005
    I have thought creating a similar function which will retrieve MSDN2 link(but not through modifying command member definition). But will MSDN2 always have the same naming scheme later on? That was what I have been afraid of... but not that it matters much :)
  • Anonymous
    December 30, 2005
    You could also register a ScriptMethod MSDN in a TYPES.MSHXML file to show the documentation in a viewer:

    <Type>
    <Name>System.Object</Name>
    <Members>
    <ScriptMethod>
    <Name>MSDN</Name>
    <Script>
    if ($global:MSDNViewer -eq $null)
    { $global:MSDNViewer = new-object -ComObject InternetExplorer.Application
    }
    $global:MSDNViewer.Navigate2("http://msdn2.microsoft.com/library/" + $this.GetType().FullName + ".ASPX")
    $global:MSDNViewer.Visible = $TRUE
    </Script>
    </ScriptMethod>
    </Members>
    </Type>


    Then you could do something like:
    [Appdomain]::CurrentDomain.MSDN()

    Jeffrey P. Snover [MSFT]
  • Anonymous
    December 30, 2005
    Now if only MSDN would provide a way for vendors to register base URLs for strong-named assemblies, this could be extended to non-MS types...
  • Anonymous
    December 31, 2005
    > Now if only MSDN would provide a way for vendors to register base
    > URLs for strong-named assemblies, this could be extended to
    > non-MS types

    Right. In lieu of that happening, the scriptMethod could do a one time load of some metadata which mapped REGEXs against the full typename to URL-maker strings (think: $URLMAKER -f $this.GetType().FullName ) where $URLMAKER for MSDN would be:
    "http://msdn2.microsoft.com/library/{0}.ASPX"

    Jeffrey P. Snover [MSFT]
  • Anonymous
    December 31, 2005
    Yup.. and if there were some standard web service contract for retrieving the information, we wouldn't need to launch in a browser -- we could merely format the information as appropriate to the display.