1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| Private Function PropertyExists(ByVal objectt As Object, ByVal propertyy As String, value As Object) As Boolean
Dim type As Type = objectt.GetType()
Dim info As System.Reflection.PropertyInfo = type.GetProperty(propertyy)
Dim reallyExists As Boolean = info IsNot Nothing
If reallyExists Then
SetValue(info, info, propertyy, value)
End If
Return reallyExists
End Function
Public Sub SetValue(ByVal info As System.Reflection.PropertyInfo,
ByVal inputObject As Object,
ByVal propertyName As String,
ByVal propertyVal As Object)
'find the property type
Dim propertyType As Type = inputObject.PropertyType
'Convert.ChangeType does not handle conversion to nullable types
'if the property type is nullable, we need to get the underlying type of the property
Dim targetType As Type = If(IsNullableType(inputObject.PropertyType), Nullable.GetUnderlyingType(inputObject.PropertyType), inputObject.PropertyType)
Try
If (Not inputObject Is Nothing AndAlso inputObject.CanWrite) Then
inputObject.SetValue(info, Convert.ChangeType(propertyVal, targetType), Nothing) '<- *** ici tombe en erreur ****
End If
Catch ex As Exception
modGlobal.MessageErreur("Erreur d'attribution valeur non valide", "Erreur d'attribution valeur " & propertyName, "Erreur dans" & info.Module.FullyQualifiedName & vbCrLf & " non valide " & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
Throw New NullReferenceException(ex.Message & vbCrLf & "Erreur d'attribution valeur " & propertyName & " non valide ")
End Try
End Sub
Private Function IsNullableType(ByVal type As Type) As Boolean
Return type.IsGenericType AndAlso type.GetGenericTypeDefinition().Equals(GetType(Nullable(Of)))
End Function
Public Function StartObjectList(ByVal AssemblyName As String, ByVal ClassName As String, ByVal StartUpObject As Object) As Boolean
Dim bRetour As Boolean = False
Try
Dim Chemin As String = IO.Path.Combine(IO.Path.GetDirectoryName(Application.ExecutablePath), AssemblyName & ".dll")
If IO.File.Exists(Chemin) Then
Dim oAssembly As System.Reflection.Assembly = Reflection.Assembly.LoadFrom(Chemin)
Dim oType As System.Type = oAssembly.GetType(ClassName)
Dim oObject As System.Object
oObject = Activator.CreateInstance(oType)
oObject.Name = ClassName.Trim
If Not oObject Is Nothing Then
If TypeOf oObject Is List(Of String) Then
For Each s As String In oObject
Next
Else
If TypeOf StartUpObject Is DataTable Then
Dim tbl As DataTable = CType(StartUpObject, DataTable)
For Each row As DataRow In tbl.Rows
For Each d As DataColumn In tbl.Columns
If PropertyExists(oObject, d.ColumnName, row.Item(d.ColumnName)) Then
End If
Next
Next
End If
End If
End If
oObject.Icon = Nothing
oObject.ShowDialog()
bRetour = True
Else
Using frm As New CustomMessageError("Erreur de chargement de DLL", "Fichier inexistant et objet non activé", "Le fichier manquant := " & Chemin)
frm.ShowDialog()
End Using
End If
Catch ex As Exception
Using frm As New CustomMessageError("Erreur de chargement de DLL", ex.Message, ex.Message & vbCrLf & ex.StackTrace)
frm.ShowDialog()
End Using
End Try
Return bRetour
End Function |
Partager