繁体   English   中英

在Powershell中,如何传递IEnumerable参数?

[英]From within Powershell, how do I pass an IEnumerable argument?

我正在尝试使用Microsoft.Lync.Model.Contact.GetContactInformation()方法。 有两个版本,一个采用普通枚举,另一个采用具有多个值的IEnumerable。

http://msdn.microsoft.com/en-us/library/lync/hh347568.aspx

我可以成功使用第一个版本(直到尝试检索没有值的版本),但是我对应该如何传入多个参数毫无意义。

$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation([int[]]("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress"))

(以上操作无效。)

有人可以向正确的方向推动我吗?

最简单的语法将与您现在拥有的语法非常接近。 该方法采用ContactInformationType值的枚举,因此您的强制转换应该是一个数组,而不是int

另外,您可以将$foobar[-1]用作$foo[$foo.Count - 1]糖,即获取最后一个元素。

$contactInfo = $c[-1].Participants[1].Contact.GetContactInformation([Microsoft.Lync.Model.ContactInformationType[]] @("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress"))

我认为,如果您尝试以下操作,它将起作用:

$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation(
                [int[]](
                        [int]Microsoft.Lync.Model::ContactInformationType.FirstName,
                        [int]Microsoft.Lync.Model::ContactInformationType.LastName,
                        [int]Microsoft.Lync.Model::ContactInformationType.DisplayName,
                        [int]Microsoft.Lync.Model::ContactInformationType.PrimaryEmailAddress))

该方法本身可能不知道“ FirstName”是什么。 尝试创建一个枚举值数组,例如:

$information = [Microsoft.Lync.Model.ContactInformationType]::FirstName, [Microsoft.Lync.Model.ContactInformationType]::LastName, [Microsoft.Lync.Model.ContactInformationType]::DisplayName, [Microsoft.Lync.Model.ContactInformationType]::PrimaryEmailAddress
$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation($information)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM