Showing posts with label GetType. Show all posts
Showing posts with label GetType. Show all posts

Sunday, 28 June 2009

Get-TypeTest.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the value, and type, of an expression. 
  4. .DESCRIPTION 
  5.     This script is a rewrite of the second example on this page, The  
  6.     script illustrates how to use the GetType method to return 
  7.     the type that results from a calculation. in this case, two  
  8.     multiplying two int32 with the Pi field results in a System.Double. 
  9. .NOTES 
  10.     File Name  : Get-TypeTest.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2009/06/get-typetestps1.html
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/58918ffs.aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\Get-TypeTest.PS1 
  20.     The type of $Radius is       : System.Int32 
  21.     Area =                         28.2743338823081 
  22.     The type is the expression is: System.Double 
  23. #> 
  24.  
  25. ## 
  26. # Start of Script 
  27. ## 
  28.   
  29. # Set and display type of radius 
  30. [int] $radius = 3 
  31. "The type of `$Radius is       : {0}" -f $radius.GetType() 
  32.  
  33. # Display Area, and the type of an expression. 
  34. "Area                           {0}" -f ($radius * $radius * [System.Math]::PI) 
  35. "The type is the expression is: {0}" -f ($radius * $radius * [System.Math]::PI).GetType() 
  36. # End of Script 

Tuesday, 11 November 2008

Get-Type.ps1

<#
.SYNOPSIS
    Uses GetType to obtain type information
.DESCRIPTION
    This script creates an object then uses the
    GetType method to return type info
.NOTES
    File Name  : Get-Type.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2
.LINK
    http://www.pshscripts.blogspot.com
.EXAMPLE
    PSH [C:\foo]: .\get-type.ps1'

    Module                     : CommonLanguageRuntimeLibrary
    Assembly                   : mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    TypeHandle                 : System.RuntimeTypeHandle
    DeclaringMethod            :
    BaseType                   : System.ValueType
    UnderlyingSystemType       : System.Int32
    FullName                   : System.Int32
    AssemblyQualifiedName      : System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561
                             34e089
    Namespace                  : System
    GUID                       : a310fadd-7c33-377c-9d6b-599b0317d7f2
    GenericParameterAttributes :
    IsGenericTypeDefinition    : False
    IsGenericParameter         : False
    GenericParameterPosition   :
    IsGenericType              : False
    ContainsGenericParameters  : False
    StructLayoutAttribute      : System.Runtime.InteropServices.StructLayoutAttribute
    Name                       : Int32
    MemberType                 : TypeInfo
    DeclaringType              :
    ReflectedType              :
    MetadataToken              : 33554629
    TypeInitializer            :
    IsNested                   : False
    Attributes                 : AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, Serializable, Befo
                                 eFieldInit
    IsVisible                  : True
    IsNotPublic                : False
    IsPublic                   : True
    IsNestedPublic             : False
    IsNestedPrivate            : False
    IsNestedFamily             : False
    IsNestedAssembly           : False
    IsNestedFamANDAssem        : False
    IsNestedFamORAssem         : False
    IsAutoLayout               : False
    IsLayoutSequential         : True
    IsExplicitLayout           : False
    IsClass                    : False
    IsInterface                : False
    IsValueType                : True
    IsAbstract                 : False
    IsSealed                   : True
    IsEnum                     : False
    IsSpecialName              : False
    IsImport                   : False
    IsSerializable             : True
    IsAnsiClass                : True
    IsUnicodeClass             : False
    IsAutoClass                : False
    IsArray                    : False
    IsByRef                    : False
    IsPointer                  : False
    IsPrimitive                : True
    IsCOMObject                : False
    HasElementType             : False
    IsContextful               : False
    IsMarshalByRef             : False
#>

##
# Start of script
##

[int] $i = 42
$type = $i.GetType()
$type | fl *
# End of script