我在powershell 4.0中试过这个:
[System.Assembly]::LoadWithPartialName("System.Collections.Generic")
$m = New-Object '[System.Collections.Generic::HashSet](String)'
$m.GetType()
但是跑步会给出错误。我的用法不正确吗?我只有2行代码!
Unable to find type [System.Assembly]. Make sure that the assembly that contains this type is loaded.
At D:\Untitled1.ps1:1 char:1
+ [System.Assembly]::LoadWithPartialName("System.Collections.Generic")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Assembly:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
New-Object : Cannot find type [[System.Collections.Generic::HashSet] (String)]: verify that the assembly containing this type is loaded.
At D:\Untitled1.ps1:2 char:6
+ $m = New-Object '[System.Collections.Generic::HashSet](String)'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At D:\Untitled1.ps1:3 char:1
+ $m.GetType()
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
答案 0 :(得分:2)
LoadWithPartialName()位于[System.Assembly]
,而不是New-Object
。此外,您的[System.Reflection.Assembly]::LoadWithPartialName("System.Collections.Generic")
$m = New-Object 'System.Collections.Generic.HashSet[String]'
$m.GetType()
语法略有偏差。
<% @page language = "java" %>
<% @page isELIgnored = "false" %>
< HTML >
< BODY >
< H2 > Session Update test < /H2>
session.setAttribute( "blah", "1234" );
session.setAttribute( "blah2", "1234" );
<%
session.setAttribute("blah", "1234");
session.setAttribute("blah2", "1234");
%>
<A href="updateSession.jsp">Update the Session info</A >
< script >
alert('Hi')
var secondsBeforeExpire = $ {
pageContext.session.maxInactiveInterval
}
var timeToDecide = 15; // Give client 15 seconds to choose.
setInterval(function() {
alert('MaxInactive Interval == ' + $ {
pageContext.session.maxInactiveInterval
})
}, 1000); < /script>
</BODY >
< /HTML>
另请参阅:http://www.leeholmes.com/blog/2006/08/18/creating-generic-types-in-powershell/