Hi jaklithn,
Thanks for your post.
Yes, in VS.net2005, it really support customized class type. We can define
a customized type, then provide a customized TypeConverter to convert this
class from/to string, then in the application setting designer, we can
explicitly set a property for My.Settings to our customized class type.
Below is a sample:
//my customized class and type converter
Public Class MyTestTypeConverter
Inherits TypeConverter
Public Overrides Function CanConvertTo(ByVal context As
ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
If (destinationType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overrides Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object, ByVal destinationType As Type) As Object
If ((Not value Is Nothing) AndAlso (destinationType Is
GetType(String))) Then
Dim mt As MyTest = CType(value, MyTest)
Return mt.Export & "," & mt.Import
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overrides Function CanConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
If (sourceType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overrides Function ConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object) As Object
Dim text1 As String = TryCast(value, String)
If (Not text1 Is Nothing) Then
Dim index As Integer = text1.IndexOf(",")
Dim mt As New MyTest
mt.Export = text1.Substring(0, index)
mt.Import = text1.Substring(index + 1)
Return mt
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
End Class
<TypeConverter(GetType(MyTestTypeConverter))> _
Public Class MyTest
Private exp As String
Public Property Export() As String
Get
Return exp
End Get
Set(ByVal value As String)
exp = value
End Set
End Property
Private imp As String
Public Property Import() As String
Get
Return imp
End Get
Set(ByVal value As String)
imp = value
End Set
End Property
End Class
In the application settings designer, I still did not find a way to use the
designer to select our class type. I have tried to deploy my class and type
converter as a separate assembly, strong name it and place it into the GAC,
the designer still igore the customized class. Currently, I just right
click Settings.settings file, use a text editor to open this file and
explicit change our "Directories" property type to "MyTest". Also, I have
changed the type in both Settings.Designer.vb and app.Config files.
Now, after the modification, I can input "ddd,ffff" in the property value
field. And at runtime, we can access/modify this property like this now:
dirExport = My.Settings.Directories.Export
dirImport = My.Settings.Directories.Import
Hope this helps
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.