venerdì 16 settembre 2011

Vb Generic Class e Generic Method

Questa è stata un filino più ostica, ma non del tutto complessa.

Al di la del fatto che il linguaggio possa piacere o meno, sono riuscito ad ottenere la mia prima classe generica.

Public Class GenericTest(Of t)

Public Function GetProperty() As PropertyInfo()


Dim actObject = Activator.CreateInstance(Of t)()

GetProperty = actObject.GetType().GetProperties()
End Function

End Class


Devo essere onesto non è nemmeno troppo bella... ma quanto meno sono riuscito a infilarci reflection e generic in un unica botta.

Module Module1

Sub Main()


Dim ents As New Entities()

Dim ttype As New GenericTest(Of Entity)()

Dim pI As PropertyInfo() = ttype.GetProperty()

For i = 0 To pI.Length - 1
Console.WriteLine(pI(i).Name)

Next
Console.ReadLine()


End Sub

End Module


E questo è il main per verificare che cosa succede, onestamente come sintassi, continuo a sostenere che sia molto più elegante e leggibile il C# ma credo che il discorso sia sempre più una questione di abitudine.

Nessun commento: