Windows Vista Forums

Is there a way of determing what a underlying value of a type shor
  1. #1


    Bob Landau Guest

    Is there a way of determing what a underlying value of a type shor

    The obvious way is simply let the powershell type system do the work as in

    [int] | Get-FrameWorkHelp

    Unfortuately there are many many types (100's) such as [Assembly],
    [ArrayList], [Calendar], ..... to name just a few that are not loaded into
    the default Powershell host. None of these can be passed via a pipe because
    the type must be known.

    However you can use the statement at the end of this post to enumerating any
    valid type as _long_ as you know the name which is why the purpose of this
    post

    This is the rough outline of what I have

    Get-FrameWorkHelp ( [object] $Type = $null, [switch] $typeName,)
    {
    if (the pipes not empty)
    {
    read from the pipe and call the UnderlyingSysteType to find the
    actual type
    }
    elseif ($Type has a valid type form "[some type]" and $TypeName is true)
    {
    How do I determine what the underlying type of "[int]"

    $Type will _always be a string type regardless of whether its in
    square
    brackets or not.
    }
    }



    I've not found enumerating the .Net namespace to work very well the below
    statement simply returns too much and changing the -like to -eq returns
    nothing

    [appdomain]::currentdomain.GetAssemblies() | ForEach {$_.GetTypes()} | Where
    {$_.Name -like 'int*'}


      My System SpecsSystem Spec

  2. #2


    Keith Hill [MVP] Guest

    Re: Is there a way of determing what a underlying value of a type shor

    "Bob Landau" <BobLandau@xxxxxx> wrote in message
    news:BDF5AE5A-E2D6-482C-B92D-74C712DAB6CB@xxxxxx

    > The obvious way is simply let the powershell type system do the work as in
    >
    > [int] | Get-FrameWorkHelp
    >
    > Unfortuately there are many many types (100's) such as [Assembly],
    > [ArrayList], [Calendar], ..... to name just a few that are not loaded
    > into
    > the default Powershell host. None of these can be passed via a pipe
    > because
    > the type must be known.
    I'm not following you. Assembly is in mscorlib so it does get loaded by
    PoSh by default.

    PS> [Reflection.Assembly] | gm -static

    TypeName: System.Reflection.Assembly

    Name MemberType Definition
    ---- ---------- ----------
    CreateQualifiedName Method static System.String
    CreateQualifiedName(String assemblyName, String typeName)
    Equals Method static System.Boolean Equals(Object objA,
    Object objB)
    ....

    > However you can use the statement at the end of this post to enumerating
    > any
    > valid type as _long_ as you know the name which is why the purpose of this
    > post
    >
    > This is the rough outline of what I have
    >
    > Get-FrameWorkHelp ( [object] $Type = $null, [switch] $typeName,)
    > {
    > if (the pipes not empty)
    > {
    > read from the pipe and call the UnderlyingSysteType to find the
    > actual type
    > }
    > elseif ($Type has a valid type form "[some type]" and $TypeName is
    > true)
    > {
    > How do I determine what the underlying type of "[int]"
    >
    > $Type will _always be a string type regardless of whether its in
    > square
    > brackets or not.
    > }
    > }
    >
    > I've not found enumerating the .Net namespace to work very well the below
    > statement simply returns too much and changing the -like to -eq returns
    > nothing
    >
    > [appdomain]::currentdomain.GetAssemblies() | ForEach {$_.GetTypes()} |
    > Where
    > {$_.Name -like 'int*'}
    >
    You would get less "noise" if you filtered out non-public types by using
    GetExportedTypes() instead:

    PS> [System.AppDomain]::CurrentDomain.GetAssemblies() |
    %{$_.GetExportedTypes()} | ?{$_.Name -match '^int\d'}

    IsPublic IsSerial Name BaseType
    -------- -------- ---- --------
    True True Int16 System.ValueType
    True True Int32 System.ValueType
    True True Int64 System.ValueType
    True False Int16Converter
    System.ComponentModel.BaseNumberConverter
    True False Int32Converter
    System.ComponentModel.BaseNumberConverter
    True False Int64Converter
    System.ComponentModel.BaseNumberConverter
    True False Int32Aggregator System.ValueType
    True False Int64Aggregator System.ValueType

    --
    Keith


      My System SpecsSystem Spec

  3. #3


    Bob Landau Guest

    Re: Is there a way of determing what a underlying value of a type

    You silly boy, Bob

    I neglicted to prepend the types with their corresponding namespace. Which
    would explain why nobody had a clue what type I passed in.

    When the type is passed via a parameter its not needed in fact I need to
    strip them away if they're provided.

    Unfortunately this made me lazy and I simply forgot that types resided in a
    namespace.

    So now change my code back to the way it was and let Powershell resolve the
    short cut.

    Thanks

    "Keith Hill [MVP]" wrote:

    > "Bob Landau" <BobLandau@xxxxxx> wrote in message
    > news:BDF5AE5A-E2D6-482C-B92D-74C712DAB6CB@xxxxxx

    > > The obvious way is simply let the powershell type system do the work as in
    > >
    > > [int] | Get-FrameWorkHelp
    > >
    > > Unfortuately there are many many types (100's) such as [Assembly],
    > > [ArrayList], [Calendar], ..... to name just a few that are not loaded
    > > into
    > > the default Powershell host. None of these can be passed via a pipe
    > > because
    > > the type must be known.
    >
    > I'm not following you. Assembly is in mscorlib so it does get loaded by
    > PoSh by default.
    >
    > PS> [Reflection.Assembly] | gm -static
    >
    > TypeName: System.Reflection.Assembly
    >
    > Name MemberType Definition
    > ---- ---------- ----------
    > CreateQualifiedName Method static System.String
    > CreateQualifiedName(String assemblyName, String typeName)
    > Equals Method static System.Boolean Equals(Object objA,
    > Object objB)
    > ...
    >

    > > However you can use the statement at the end of this post to enumerating
    > > any
    > > valid type as _long_ as you know the name which is why the purpose of this
    > > post
    > >
    > > This is the rough outline of what I have
    > >
    > > Get-FrameWorkHelp ( [object] $Type = $null, [switch] $typeName,)
    > > {
    > > if (the pipes not empty)
    > > {
    > > read from the pipe and call the UnderlyingSysteType to find the
    > > actual type
    > > }
    > > elseif ($Type has a valid type form "[some type]" and $TypeName is
    > > true)
    > > {
    > > How do I determine what the underlying type of "[int]"
    > >
    > > $Type will _always be a string type regardless of whether its in
    > > square
    > > brackets or not.
    > > }
    > > }
    > >
    > > I've not found enumerating the .Net namespace to work very well the below
    > > statement simply returns too much and changing the -like to -eq returns
    > > nothing
    > >
    > > [appdomain]::currentdomain.GetAssemblies() | ForEach {$_.GetTypes()} |
    > > Where
    > > {$_.Name -like 'int*'}
    > >
    >
    > You would get less "noise" if you filtered out non-public types by using
    > GetExportedTypes() instead:
    >
    > PS> [System.AppDomain]::CurrentDomain.GetAssemblies() |
    > %{$_.GetExportedTypes()} | ?{$_.Name -match '^int\d'}
    >
    > IsPublic IsSerial Name BaseType
    > -------- -------- ---- --------
    > True True Int16 System.ValueType
    > True True Int32 System.ValueType
    > True True Int64 System.ValueType
    > True False Int16Converter
    > System.ComponentModel.BaseNumberConverter
    > True False Int32Converter
    > System.ComponentModel.BaseNumberConverter
    > True False Int64Converter
    > System.ComponentModel.BaseNumberConverter
    > True False Int32Aggregator System.ValueType
    > True False Int64Aggregator System.ValueType
    >
    > --
    > Keith
    >

      My System SpecsSystem Spec

Is there a way of determing what a underlying value of a type shor problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace document underlying XPathNavigator object RR .NET General 0 22 Apr 2009
what is the underlying compress command used ? Hassan Vista General 1 16 Dec 2007
Display actual file type, not description of the type Doug Vista file management 3 12 Oct 2007
Display the actual type, rather than the description of the type Doug Vista General 4 11 Oct 2007
Unable to find type [Drawing.Image]: make sure that the assembly containing this type is loaded IT Staff PowerShell 4 16 Aug 2007