Lotus & VB.NET(2):准备工作

水如烟 2009-07-11 10:24:35
类及其作用:

SecurePassword 存储密码。自动登录用。

IniFile 配置文件即ini文件的读取

Converter 转换类型

Collection 对象组的遍历

IComClassBase 实现com对象类的基类

上一篇:Lotus & VB.NET(1):说明
...全文
142 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
paulin 2009-07-12
  • 打赏
  • 举报
回复
学习,jf
LQknife 2009-07-12
  • 打赏
  • 举报
回复
顶啊
水如烟 2009-07-12
  • 打赏
  • 举报
回复
Collection.vb
Namespace LzmTW.uSystem
Public Class Collection
Private Sub New()
End Sub

Public Shared Sub ForEach(Of T)(ByVal arrayObject As Object, ByVal action As Action(Of T))
If arrayObject Is Nothing Then Return

Dim type As Type = arrayObject.GetType

If type.IsArray Then

ForEach(Of T)(CType(arrayObject, Array), action)
ElseIf type Is GetType(List(Of T)) Then

ForEach(Of T)(CType(arrayObject, List(Of T)), action)
Else
action(Converter.ChangeTo(Of T)(arrayObject))
End If
End Sub

Public Shared Sub ForEach(Of T)(ByVal list As List(Of T), ByVal action As Action(Of T))
If list Is Nothing Then Return

ForEach(Of T)(list.GetEnumerator, action)
End Sub

Public Shared Sub ForEach(Of T)(ByVal array As IEnumerable(Of T), ByVal action As Action(Of T))
If array Is Nothing Then Return

ForEach(Of T)(array.GetEnumerator, action)
End Sub

Public Shared Sub ForEach(Of T)(ByVal array As IEnumerator(Of T), ByVal action As Action(Of T))
If array Is Nothing Then Return

With array
While .MoveNext
action(.Current)
End While
End With
End Sub

Public Shared Sub ForEach(Of T)(ByVal array As IEnumerable, ByVal action As Action(Of T))
If array Is Nothing Then Return

ForEach(Of T)(array.GetEnumerator, action)
End Sub

Public Shared Sub ForEach(Of T)(ByVal array As IEnumerator, ByVal action As Action(Of T))
If array Is Nothing Then Return

With array
While .MoveNext
action(Converter.ChangeTo(Of T)(.Current))
End While
End With
End Sub

Public Shared Function GetList(Of T)(ByVal arrayObject As Object) As List(Of T)
Dim helper As New GetObject(Of T)

ForEach(Of T)(arrayObject, AddressOf helper.Action)

Return helper.Result
End Function

Private Class GetObject(Of T)
Private List As New List(Of T)

Public Sub Action(ByVal value As T)
List.Add(value)
End Sub

Public ReadOnly Property Result() As List(Of T)
Get
Return List
End Get
End Property

End Class
End Class

End Namespace
水如烟 2009-07-11
  • 打赏
  • 举报
回复
IComClassBase.vb
Namespace LzmTW.uSystem
Public MustInherit Class IComClassBase(Of T)
Implements IDisposable

Private internalCom As T

Sub New(ByVal com As T)
Me.internalCom = com
End Sub

Public ReadOnly Property com() As T
Get
Return Me.internalCom
End Get
End Property

Public ReadOnly Property IsValid() As Boolean
Get
Return Not Me.internalCom Is Nothing
End Get
End Property

Protected Overridable Sub ReleaseOtherComsBeforeReleaseMainCom()
End Sub

Protected Overridable Sub DisposeObjectsBeforeReleaseMainCom()
End Sub

Public Function GetList(Of V)(ByVal arrayObject As Object) As List(Of V)
Return Collection.GetList(Of V)(arrayObject)
End Function

Public Sub ForEach(Of V)(ByVal arrayObject As Object, ByVal action As Action(Of V))
Collection.ForEach(Of V)(arrayObject, action)
End Sub

Public Function ChangeTo(Of V)(ByVal value As Object) As V
Return Converter.ChangeTo(Of V)(value)
End Function

Protected Sub ReleaseCom(ByVal com As Object)
If Not com Is Nothing AndAlso Marshal.IsComObject(com) Then
Marshal.ReleaseComObject(com)
com = Nothing
End If
End Sub

Private disposedValue As Boolean = False

Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then

Me.DisposeObjectsBeforeReleaseMainCom()
End If

Me.ReleaseOtherComsBeforeReleaseMainCom()

Me.ReleaseCom(Me.internalCom)

End If

Me.disposedValue = True
End Sub

Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
GC.Collect(2)
End Sub

End Class
End Namespace
HanMo 2009-07-11
  • 打赏
  • 举报
回复
一帐号只能连续回复三次
水如烟 2009-07-11
  • 打赏
  • 举报
回复
Converter.vb
Namespace LzmTW.uSystem
Public Class Converter
Private Sub New()
End Sub

Public Shared Function ChangeTo(Of T)(ByVal value As Object) As T
If value Is Nothing Then Return Nothing

Return CType(Microsoft.VisualBasic.CompilerServices.Conversions.ChangeType(value, GetType(T)), T)
End Function

End Class
End Namespace
水如烟 2009-07-11
  • 打赏
  • 举报
回复
IniFile.vb
Namespace LzmTW.uSystem
Public Class iniFile
Private gFile As String
Private gCurrentSection As String

Public Property File() As String
Get
Return gFile
End Get
Set(ByVal value As String)
gFile = value
End Set
End Property

Public Property CurrentSection() As String
Get
Return gCurrentSection
End Get
Set(ByVal value As String)
gCurrentSection = value
End Set
End Property

Public Function GetValue(ByVal key As String) As String
Return GetValue(key, Me.CurrentSection, Me.File)
End Function

Public Function SetValue(ByVal key As String, ByVal value As String) As Boolean
Return SetValue(key, value, Me.CurrentSection, Me.File)
End Function

Public Shared Function SetValue(ByVal key As String, ByVal value As String, ByVal section As String, ByVal file As String) As Boolean
Return WritePrivateProfileString(section, key, value, file)
End Function

Public Shared Function GetValue(ByVal key As String, ByVal section As String, ByVal file As String) As String
Dim mResult As New System.Text.StringBuilder(" ", 260)
GetPrivateProfileStringA(section, key, "", mResult, mResult.Capacity, file)
Return mResult.ToString
End Function

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
ByVal lpSectionName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String _
) As Boolean

Private Declare Function GetPrivateProfileStringA Lib "kernel32.dll" ( _
ByVal lpSectionName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String _
) As Integer

End Class
End Namespace
水如烟 2009-07-11
  • 打赏
  • 举报
回复
SecurePassword.vb

Namespace LzmTW.uSystem
Public Class SecurePassword

Private Password As Security.SecureString

Public ReadOnly Property SecureString() As Security.SecureString
Get
Return Password
End Get
End Property

Public Sub Reset(ByVal pass As String)
Me.Release()

If pass Is Nothing Then Return
pass = pass.Trim
If pass.Equals(String.Empty) Then Return

Password = New Security.SecureString

For Each c As Char In pass.ToCharArray
Password.AppendChar(c)
Next

Password.MakeReadOnly()
End Sub

Public Sub Release()
If Password Is Nothing Then Return

Password.Dispose()
Password = Nothing
End Sub

End Class
End Namespace
dylike 2009-07-11
  • 打赏
  • 举报
回复
GetPoints 接分

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧