Imports System.ComponentModel
Imports System.ComponentModel.TypeDescriptor
Imports ColorBlender.cBlenderItems
Imports System.Drawing.Drawing2D
#Region "BlendItemsConverter"
<System.Diagnostics.DebuggerStepThrough()>
Friend Class BlendItemsConverter : Inherits ExpandableObjectConverter
Public Overrides Function GetCreateInstanceSupported(ByVal context As ITypeDescriptorContext) As Boolean
Return True
End Function
Public Overrides Function CreateInstance(ByVal context As ITypeDescriptorContext, ByVal propertyValues As IDictionary) As Object
Dim bItem As New cBlenderItems() With
{
.cbColor = CType(propertyValues("cbColor"), Color()),
.cbPosition = CType(propertyValues("cbPosition"), Single()),
.BorderColor = CType(propertyValues("BorderColor"), Color),
.FocalPoints = CType(propertyValues("FocalPoints"), cFocalPoints),
.BlendGradientType = CType(propertyValues("BlendGradientType"), eBlendGradientType),
.BlendGradientMode = CType(propertyValues("BlendGradientMode"), LinearGradientMode),
.BlendPathShape = CType(propertyValues("BlendPathShape"), eBlendPathShape)
}
Return bItem
End Function
Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If (sourceType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, _
ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
'cONVERT THE
If TypeOf value Is String Then
Dim s As String() = Split(CType(value, String), "|")
Try
Dim bColors As New List(Of Color)
Dim bPoints As New List(Of Single)
For Each cstring As String In Split(s(1), ";")
bColors.Add(GetConverter(GetType(Color)).ConvertFromString(cstring))
Next
For Each cstring As String In Split(s(2), ";")
bPoints.Add(GetConverter(GetType(Single)).ConvertFromString(cstring))
Next
Return New cBlenderItems(bColors.ToArray, bPoints.ToArray,
GetConverter(GetType(Color)).ConvertFromString(s(0)),
GetConverter(GetType(cFocalPoints)).ConvertFromString(s(3)),
GetConverter(GetType(eBlendGradientType)).ConvertFromString(s(4)),
GetConverter(GetType(LinearGradientMode)).ConvertFromString(s(5)),
GetConverter(GetType(eBlendPathShape)).ConvertFromString(s(6))
)
Catch ex As Exception
Throw New ArgumentException(String.Format(
"Can not convert '{0}' to type cBlenderItems {1}",
CStr(value),
ex.Message))
End Try
Else
Return New cBlenderItems()
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
#Region "Test"
Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, _
ByVal culture As System.Globalization.CultureInfo, _
ByVal value As Object, ByVal destinationType As Type) As Object
If (destinationType Is GetType(String) AndAlso TypeOf value Is cBlenderItems) Then
Return CType(value, cBlenderItems).ToString
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
#End Region
End Class
#End Region