Bonjour,
Peut-être ainsi
Une classe de test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Public Class TestProp
Public Shared ValeurShared As String = "coucou"
Private _ChaineAffectee As String = "Propriété affectée !"
Public Property ChaineAffectee() As String
Get
Return _ChaineAffectee
End Get
Set(ByVal value As String)
_ChaineAffectee = value
End Set
End Property
Private _chainenothing As String = Nothing
Public Property chainenothing() As String
Get
Return _chainenothing
End Get
Set(ByVal value As String)
_chainenothing = value
End Set
End Property
Sub dispose()
ValeurShared = Nothing
End Sub
End Class |
Pour un accés aux propriétés et mettre à nothing
1 2 3 4 5 6 7 8 9 10 11
| Sub litPropriete(tc As TestProp)
For Each prop As Reflection.PropertyInfo In tc.GetType().GetProperties
If Not tc.GetType().GetProperty(prop.Name).GetValue(tc, Nothing) Is Nothing Then
MessageBox.Show(prop.Name & " : " & tc.GetType().GetProperty(prop.Name).GetValue(tc, Nothing).ToString)
tc.GetType().GetProperty(prop.Name).SetValue(tc, Nothing, Nothing) ' affecte nothing
If tc.GetType().GetProperty(prop.Name).GetValue(tc, Nothing) Is Nothing Then MessageBox.Show(prop.Name & " : nothing")
Else
MessageBox.Show(prop.Name & " : nothing")
End If
Next
End Sub |
Pour un accés aux champs shared et mettre à nothing
1 2 3 4 5 6 7 8 9 10 11 12
| Sub litChamps(tc As TestProp)
For Each prop As Reflection.FieldInfo In tc.GetType().GetFields
If Not tc.GetType().GetField(prop.Name).GetValue(tc) Is Nothing Then
MessageBox.Show(prop.Name & " : " & tc.GetType().GetField(prop.Name).GetValue(tc).ToString)
tc.GetType().GetMethod("dispose").Invoke(tc, Nothing) ' testé ok
'tc.GetType().GetField(prop.Name).SetValue(tc, Nothing) ' affecte nothing 'remplacé par l'appel à la méthode
If tc.GetType().GetField(prop.Name).GetValue(tc) Is Nothing Then MessageBox.Show(prop.Name & " : nothing")
Else
MessageBox.Show(prop.Name & " : nothing")
End If
Next
End Sub |
appel pour test
1 2 3
| Dim t As New TestProp
litpropriete(t)
litChamps(t) |
J'ai regardé rapidement, j'espère que cela t'apportera quelques idées. (j'ai rajouté la partie dispose pas testé, elle fait partie de la classe à voir si on peut avoir le même principe sur la variable , mais les réponses arrivent avant que j'ai fini, alors je met déjà ça
)
Edit
J'ai testé pour l'appel de la méthode (toujours sur la classe elle même)
tc.GetType().GetMethod("dispose").Invoke(tc, Nothing) ' testé ok
Corrigé dans le code
Reste à voir sur la variable shared (je te laisse regarder)
Partager