I would like to use a class that ProvideProperty as object inside the disigner but it seems I can't use it when the property is an Object. A string works well.
I can set and get within the code but not in the designer.
Big thx
My code :
Imports System.Windows.Forms
Imports System.ComponentModel
<ProvideProperty("Champ", GetType(Control))> _
<ProvideProperty("Valeur", GetType(Control))> _
<ProvideProperty("Comparaison", GetType(Control))> _
Public Class ProprietesEtendues
Implements IExtenderProvider
Public Enum CompareType
Egal
Different
PlusGrand
PlusGrandEgal
PlusPetit
PlusPetitEgal
End Enum
Private _champ As New Dictionary(Of IntPtr, String)
Private _val As New Dictionary(Of IntPtr, Object)
Private _comp As New Dictionary(Of IntPtr, CompareType)
'Propriété Comparaison
Public Function GetChamp(ByVal c As Control) As String
Dim strRetour As String = ""
_champ.TryGetValue(c.Handle, strRetour)
Return strRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type String")> _
Public Sub SetChamp(ByVal c As Control, ByVal value As String)
_champ(c.Handle) = value
End Sub
'Propriété Valeur
Public Function GetValeur(ByVal c As Control) As Object
Dim objRetour As Object = ""
_val.TryGetValue(c.Handle, objRetour)
Return objRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type Object")> _
Public Sub SetValeur(ByVal c As Control, ByVal value As Object)
_val(c.Handle) = value
End Sub
'Propriété Comparaison
Public Function GetComparaison(ByVal c As Control) As CompareType
Dim ctRetour As CompareType = CompareType.Egal
_comp.TryGetValue(c.Handle, ctRetour)
Return ctRetour
End Function
<DefaultValue(CompareType.Egal), Category("Data"), Description("Ajoute une propriété de type CompareType")> _
Public Sub SetComparaison(ByVal c As Control, ByVal value As CompareType)
_comp(c.Handle) = value
End Sub
Public Function CanExtend(ByVal target As [Object]) As Boolean Implements IExtenderProvider.CanExtend
Return True
End Function
End Class
Normaly, you can put at least a string like the Tag property
If a string is good enough then you can apply the [TypeConverter] attribute:
<TypeConverter(GetType(StringConverter))> _
Public Function GetValeur(ByVal c As Control) As Object
Dim objRetour As Object = ""
_val.TryGetValue(c.Handle, objRetour)
Return objRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type Object")> _
<TypeConverter(GetType(StringConverter))> _
Public Sub SetValeur(ByVal c As Control, ByVal value As Object)
_val(c.Handle) = value
End Sub