在InterIMAP中将C#转换为PowerShell [英] Translating C# to PowerShell in InterIMAP

查看:57
本文介绍了在InterIMAP中将C#转换为PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerShell脚本中使用C#时遇到问题.我要使用的库是InterIMAP

I'm having a problem with using C# in my PowerShell script. The library I'm trying to use is InterIMAP

具体地说,我正在尝试转换此构造函数:

Specifically, I am trying to convert this constructor:

using InterIMAP;

IMAPConfig config = new IMAPConfig("server","username","password", true, false, "INBOX");

到目前为止我拥有的PowerShell脚本:

The PowerShell script I have so far:

$loadLib =[Reflection.Assembly]::LoadFile('C:\Users\......\InterIMAP.dll);

$config= [InterIMAP.IMAP.IMAPConfig]::IMAPConfig("imap.gmail.com", $user, $password, $true, $true, "INBOX");

我认为我遇到的问题是因为IMAP类具有指向IMAPConfig类的指针:

I think the issue I'm having is because the IMAP class has a pointer to the IMAPConfig class: http://interimap.codeplex.com/SourceControl/latest#InterIMAP/InterIMAP/Client/IMAP.cs

我一定做错了.任何帮助表示赞赏

I must be doing something wrong. Any help appreciated

推荐答案

在PowerShell代码中,您正在作为IMAPConfig类的静态方法访问IMAPConfig(),我猜这是无效的.为了在PowerShell中使用对象构造函数,您需要使用New-Object cmdlet.

In your PowerShell code, you're accessing IMAPConfig() as a static method of the IMAPConfig class, which I'm guessing is not valid. In order to use an object constructor in PowerShell, you need to use the New-Object cmdlet.

-TypeName参数指定要实例化的.NET类. -ArgumentList参数接受表示构造函数参数的任意System.Object对象的数组.

The -TypeName parameter specifies the .NET class that you want to instantiate. The -ArgumentList parameter accepts an array of arbitrary System.Object objects that represent the constructor parameters.

$config = New-Object -TypeName InterIMAP.IMAP.IMAPConfig -ArgumentList @('imap.gmail.com', $User, $Password, $true, $true, 'INBOX');

这篇关于在InterIMAP中将C#转换为PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆