[VB.NET 2.0] Generic methods should provide type parameter

Pagina: 1
Acties:

  • BasSpruit
  • Registratie: September 2002
  • Laatst online: 09-04-2022
Ik heb een stukje code in mijn vb progsel staan:
Visual Basic:
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
Public Function LoadFromFile(Of T As {TranslationBase, New})(ByVal FilePath As String) As T
        Dim NewObject As T = Nothing
        Dim TheSerializer As New Xml.Serialization.XmlSerializer(NewObject.GetType)

        'If the file was not found, throw an error
        If Not System.IO.File.Exists(FilePath) Then
            'Throw New System.IO.FileNotFoundException("404!", FilePath)
        Else
            'Create a reader (directory and file where found)
            Dim Info As New System.IO.FileInfo(FilePath)
            Dim Filestream As System.IO.FileStream = Info.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)
            Dim TheReader As New XmlTextReader(Filestream)

            'If it is possible to DeSerialize, do it
            If TheSerializer.CanDeserialize(TheReader) Then
                NewObject = CType(TheSerializer.Deserialize(TheReader), T)
            End If

            TheReader.Close()
            Filestream.Dispose()

        End If

        Return NewObject
    End Function


nu ben ik met FxCop bezig, en die geeft
Generic methods should provide type parameter
als bericht, evenals de volgende url: http://www.gotdotnet.com/...ProvideTypeParameter.html

Ik heb echter geen idee wat ik hiermee aan moet. ik heb al geprobeerd mijn functie te herschrijven naar
Visual Basic:
1
2
Public Function LoadFromFile(Of T As {TranslationBase, New})(ByVal Type as T, ByVal FilePath As String) As T
' ...
zoals aangegeven maar mijn call gaat dan mis (wat ik ook probeer). Behalve dan als ik een extra parameter meegeef, maar dan zegt FxCop weer dat ik een unused parameter heb.

Wat kan ik het beste doen?