【发布时间】:2015-07-14 13:24:10
【问题描述】:
我创建了一个自定义对象,但我似乎无法将数组传递给它。我将在下面粘贴我的代码。我要传递的数组是“UserProxies”。
我的对象:
Public Class obj
Public isPrimary As String
Public AccountName As String
Public DisplayName As String
Public mail As String
Public DistinguishName As String
Public HomeDirectory As String
Public EmployeeId As String
Public Description As String
Public HomeDrive As String
Public ScriptPath As String
Public telephoneNumber As String
Public mobile As String
Public streetAddress As String
Public City As String
Public Province As String
Public Country As String
Public postalCode As String
Public company As String
Public EmployeeTitle As String
Public profilePath As String
Public homeMDB As String
Public legacyExchangeDN As String
Public TargetAddress As String
Public Enabled As String
Public IsAccountLockedOut As String
Public BadLogonCount As String
Public LastBadPasswordAttempt As String
Public LastLogon As String
Public LastPasswordSet As String
Public ActiveSync As String
Public UserProxies() As String
Sub New(isprimary As String, AccountName As String, DisplayName As String, mail As String, DistinguishName As String, HomeDirectory As String, EmployeeId As String, Description As String, HomeDrive As String, ScriptPath As String, telephoneNumber As String, mobile As String, streetAddress As String, City As String, Province As String, Country As String, postalCode As String, company As String, EmployeeTitle As String, profilePath As String, homeMDB As String, legacyExchangeDN As String, TargetAddress As String, Enabled As String, IsAccountLockedOut As String, BadLogonCount As String, LastBadPasswordAttempt As String, LastLogon As String, LastPasswordSet As String, ActiveSync As String, UserProxies() As String)
Me.isPrimary = isprimary
Me.AccountName = AccountName
Me.DisplayName = DisplayName
Me.mail = mail
Me.DistinguishName = DistinguishName
Me.HomeDirectory = HomeDirectory
Me.EmployeeId = EmployeeId
Me.Description = Description
Me.HomeDrive = HomeDrive
Me.ScriptPath = ScriptPath
Me.telephoneNumber = telephoneNumber
Me.mobile = mobile
Me.streetAddress = streetAddress
Me.City = City
Me.Province = Province
Me.Country = Country
Me.postalCode = postalCode
Me.company = company
Me.EmployeeTitle = EmployeeTitle
Me.profilePath = profilePath
Me.homeMDB = homeMDB
Me.legacyExchangeDN = legacyExchangeDN
Me.TargetAddress = TargetAddress
Me.Enabled = Enabled
Me.IsAccountLockedOut = IsAccountLockedOut
Me.BadLogonCount = BadLogonCount
Me.LastBadPasswordAttempt = LastBadPasswordAttempt
Me.LastLogon = LastLogon
Me.LastPasswordSet = LastPasswordSet
Me.ActiveSync = ActiveSync
Me.UserProxies = UserProxies
End Sub
End Class
我在哪里填写:
Public Shared UserProxies() As String 'The Public part is normal
If UserDirectory.Properties("proxyAddresses").Value IsNot Nothing Then
Dim ProxiesObj As Object = UserDirectory.Properties("proxyAddresses").Value 'Proxy to put into object first
Dim x As Integer = 0
For Each Item As String In ProxiesObj
ReDim Preserve UserProxies(x)
UserProxies(x) = Item
x = x + 1
Next
End If
UserObject.add(New obj(PrimaryAccount, AccountName, DisplayName, mail, DistinguishName, HomeDirectory, EmployeeId, Description, HomeDrive, ScriptPath, telephoneNumber, mobile, streetAddress, City, Province, Country, postalCode, company, EmployeeTitle, profilePath, homeMDB, legacyExchangeDN, TargetAddress, Enabled, IsAccountLockedOut, BadLogonCount, LastBadPasswordAttempt, LastLogon, LastPasswordSet, ActiveSync, UserProxies))
我在运行时收到错误消息:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
其余的工作正常。错误消息仅在我将数组添加到其中时才开始。
感谢您的帮助。
【问题讨论】:
-
ProxiesObj实际上是什么?你用过调试器吗? -
这是一个来自活动目录对象“proxyAddresses”的对象。它包含 Exchange 代理
-
它是什么类型,是自定义类型还是框架之一?它是否实现了
IEnumerable(Of String)?否则你不能在For.. Each中使用它。 -
这个对象工作正常。我只是发现我的问题比这简单得多。只是一个声明不够大的输出的数组......不过谢谢!
-
理想情况下,您应该使用
.Properties("proxyAddresses")作为PropertyValueCollection