Torna al Thread
Public Class Classe_Ana_Valutatori
Public Function FindValutatori(ByVal codice_valut As Nullable(Of Integer), ByVal nome_valut As String, ByVal cognome_valut As String) As List(Of FoundDatiValut)
Dim findvalut As New List(Of FoundDatiValut)
Try
Using connection As New OnEntities
Dim query = From Valut In connection.T_ANA_VALUTATORI _
Where (Valut.VALUT_CODICE = codice_valut Or codice_valut Is Nothing) And (Valut.VALUT_NOME = nome_valut Or nome_valut = " ") And _
(Valut.VALUT_COGNOME = cognome_valut Or cognome_valut = " ") _
Select Codice = Valut.VALUT_CODICE, Nome = Valut.VALUT_NOME,Cognome = Valut.VALUT_COGNOME, Stato = Valut.VALUT_STATO
Dim lista = query.ToList()
Dim m As New mapper(Of FoundDatiValut)
findvalut = m.mappa(lista)
Return findvalut
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function
Public Class mapper(Of OutType)
Public Function mappa(ByVal list As IList) As List(Of OutType)
Dim pInfosFrom(), pInfo As System.Reflection.PropertyInfo
Dim i, j As Integer
Dim objClass, objVal As Object
Dim retList As New List(Of OutType)
Dim tipo As Type = GetType(OutType)
For i = 0 To list.Count - 1
pInfosFrom = list(i).GetType.GetProperties()
objClass = tipo.Assembly.CreateInstance(tipo.FullName)
For j = 0 To pInfosFrom.Length - 1
pInfo = tipo.GetProperty(pInfosFrom(j).Name)
If Not pInfo Is Nothing Then
objVal = pInfosFrom(j).GetValue(list(i), Nothing)
If pInfo.PropertyType Is GetType(Nullable) Then
Else
pInfo.SetValue(objClass, objVal, Nothing)
End If
End If
Next
retList.Add(CType(objClass, OutType))
Next
Return retList
End Function
End Class
Public Class FoundDatiValut
Public _Codice As Nullable(Of Integer)
Public Property Codice() As Nullable(Of Integer)
Get
Return _Codice
End Get
Set(ByVal value As Nullable(Of Integer))
_Codice = value
End Set
End Property
Public _Nome As String
Public Property Nome() As String
Get
Return _Nome
End Get
Set(ByVal value As String)
_Nome = value
End Set
End Property
Public _Cognome As String
Public Property Cognome() As String
Get
Return _Cognome
End Get
Set(ByVal value As String)
_Cognome = value
End Set
End Property
Public _Stato As String
Public Property Stato() As String
Get
Return _Stato
End Get
Set(ByVal value As String)
_Stato = value
End Set
End Property
End Class
End Class