.net - Can I use System.Core.dll/System.Collections.Generic.HashSet in powershell? -


i'd use hashset in powershell script. think i've figured out how instantiate generic collection objects doing:

[type] $strtype = "string" $listclass = [system.collections.generic.list``1] $listobject = $base.makegenerictype(@($t)) $mylist = new-object $setobject 

this works fine lists , dictionaries, when try create hashset get:

unable find type [system.collections.generic.hashset`1]: make sure assembly containing type loaded. 

so looks need load system.core.dll can't seem powershell load assembly. example calling [system.reflection.assembly]::loadwithpartialname("system.core") causes exception:

"loadwithpartialname" "1" argument(s): "could not load file or assembly 'system.core, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089' or 1 of dependencies. system cannot find file specified." 

any pointers?

powershell 2.0 makes easier 1) adding add-type cmdlet loading assembly , 2) updates syntax make specifying closed generic type name simpler e.g.:

ps> add-type -assemblyname system.core ps> $h = new-object 'system.collections.generic.hashset[string]' ps> $h.add('f') true 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -