You'd need a non-generic base class or interface containing the members of your class which don't rely on the generic type parameter.
Public MustInherit Class EventSerializer
Public Shared Function Create(Of TEvent As {New, IEvent})(ByVal evt As TEvent) As EventSerializer(Of TEvent)
Return Create(Of TEvent)()
End Function
Public Shared Function Create(Of TEvent As {New, IEvent})() As EventSerializer(Of TEvent)
End Function
Public Shared Function Create(ByVal evtType As Type) As EventSerializer
Dim method As MethodInfo = GetType(EventSerializer).GetMethod("Create", BindingFlags.Public Or BindingFlags.Static, Nothing, Type.EmptyTypes, Nothing)
Dim result As Object = method.MakeGenericMethod(evtType).Invoke(Nothing, Nothing)
Return DirectCast(result, EventSerializer)
End Function
End Class
Public Class EventSerializer(Of TEvent As {New, IEvent})
Inherits EventSerializer
End Class
You might want to cache the MethodInfo
for the generic method in a shared field, to avoid the overhead of finding it each time you call the non-generic factory method.