0
我使用下面的代碼從Outlook檢索特定的地址簿:PowerShell的C#轉換comobject到.NET
$outlook = $(New-Object -ComObject Outlook.Application)
$Session = $outlook.Session
$Session.Logon()
$ab = $Session.AddressLists | ? {$_.Name -eq 'test'}
然後嘗試使用C#轉換的$ab
對象使用以下到.NET:
$source = @"
using Microsoft.Office.Interop.Outlook;
public unsafe static class OAB
{
public static void List(object Stream)
{
var i = Stream as Microsoft.Office.Interop.Outlook.AddressList;
return i;
}
}
"@
$cp = new-object System.CodeDom.Compiler.CompilerParameters
$cp.CompilerOptions = "/unsafe"
$cp.ReferencedAssemblies.Add('C:\wkdir\refassem\Microsoft.Office.Interop.Outlook.dll')
Add-Type -TypeDefinition $source -CompilerParameters $cp
我收到的錯誤是:
Since 'OAB.List(object)' returns void, a return keyword must not be followed by an object expression
聲明,我是個完滿成功新手到C#所以對我來說很容易!