Methods

As well as describing the connection, the web service proxy object exposes methods used to interact with the web service.

Get-Member can be used to view the methods. The methods beginning with Get are shown following:

PS> $periodicTable | Get-Member Get* -MemberType Method | Select-Object Name, Definition 
 
Name                  Definition                                                                                                              
----                  ----------                                                                                                              
GetAtomicNumber       string GetAtomicNumber(string ElementName)                                                                              
GetAtomicNumberAsync  voidGetAtomicNumberAsync(string ElementName), ... 
GetAtomicWeight       string GetAtomicWeight(string ElementName)                                                                              
GetAtomicWeightAsync  voidGetAtomicWeightAsync(string ElementName), ... 
GetAtoms              string GetAtoms() 
GetAtomsAsync         void GetAtomsAsync(), ... 
GetElementSymbol      string GetElementSymbol(string ElementName)                                                                             
GetElementSymbolAsync void GetElementSymbolAsync(string ElementName), ... 
GetHashCodeintGetHashCode() 
GetLifetimeServiceSystem.ObjectGetLifetimeService() 
GetType               type GetType() 

The GetAtoms method will list the names of each of the elements in the periodic table. The name of an element can be used to retrieve simple information using the other methods, for example:

PS> $periodicTable.GetAtomicNumber('Zirconium') 
<NewDataSet> 
<Table> 
<AtomicNumber>40</AtomicNumber> 
<ElementName>Zirconium</ElementName> 
<Symbol>Zr</Symbol> 
<AtomicWeight>91.22</AtomicWeight> 
<BoilingPoint>3851</BoilingPoint> 
<IonisationPotential>6.8500000000000005</IonisationPotential> 
<EletroNegativity>1.22</EletroNegativity> 
<AtomicRadius>1.45</AtomicRadius> 
<MeltingPoint>2125</MeltingPoint> 
<Density>6511</Density> 
</Table> 
</NewDataSet> 

As this interface does not define structured types, the value returned is an XML string. PowerShell can use the XML type accelerator to turn this into an object:

PS> ([Xml]$periodicTable.GetAtomicNumber('Einsteinium')).NewDataSet.Table 
 
AtomicNumber     : 99 
ElementName      : Einsteinium 
Symbol           : Es 
AtomicWeight     : 255 
BoilingPoint     : 1500 
EletroNegativity : 1.2 
MeltingPoint     : 860  

The property values, such as the MeltingPoint, are strings and would need to be converted to numeric values if there was a need to compare values:

PS> $hydrogen = ([Xml]$periodicTable.GetAtomicNumber('Hydrogen')).NewDataSet.Table 
$hydrogen.MeltingPoint.GetType() 
 
IsPublic IsSerial Name                     BaseType 
-------- -------- ----                     --------  
True     True     String                   System.Object 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.239.166