Visual Studio报告该属性没有getter,即使intellisense说它确实如此

时间:2012-05-20 11:35:53

标签: c# ldap

我正在使用LDAP连接类,工作于this page on MSDN

我使用字符串构造函数实例化了类,如下所示:

LdapConnection ld = new LdapConnection("LDAP://8.8.8.8:8888");

我现在想要设置我的凭据,所以我尝试执行以下操作:

ld.Credential.UserName = "Foo";

但是我收到以下错误:

  

属性或索引器'System.DirectoryServices.Protocols.DirectoryConnection.Credential'不能在此上下文中使用,因为它缺少get访问器。

但是,输入时,intellisense会显示以下内容:

enter image description here

此描述表明UserName确实应该有一个Get Accessor,我缺少什么?

由于

1 个答案:

答案 0 :(得分:6)

LdapConnection.Credential Property没有get访问者,因此您无法检索其当前值并在返回的NetworkCredential实例上设置UserName属性。您只能分配给LdapConnection.Credential属性:

ld.Credential = new NetworkCredential(userName, password);

var credential = new NetworkCredential();
credential.UserName = userName;
credential.Password = password;
ld.Credential = credential;

ld.Credential = new NetworkCredential
{
    UserName = userName,
    Password = password,
};