Hi!
Ich versuch gerade ein C# Projekt nach vb.net zu konvertieren.
Leider wandelt der Visual Studio Converter nicht alles korrekt um.
Er erstellt eine bzw. zwei Funktionen die CSharpImpl __Assign bzw. __Throw benutzen..(Obsolete)
..ich hätte dies gern ausgemerzt.
Ist dieser Code korrekt?:
Quelle C#:
Spoiler anzeigen
wurde zu:
Spoiler anzeigen
Ich hätte das jetzt so übersetzt:
Spoiler anzeigen
Ist das so korrekt?
Ich versuch gerade ein C# Projekt nach vb.net zu konvertieren.
Leider wandelt der Visual Studio Converter nicht alles korrekt um.
Er erstellt eine bzw. zwei Funktionen die CSharpImpl __Assign bzw. __Throw benutzen..(Obsolete)
..ich hätte dies gern ausgemerzt.
Ist dieser Code korrekt?:
Quelle C#:
VB.NET-Quellcode
-
- public CommentFrame([NotNull] string comment, [NotNull] string description)
- {
- Comment = comment ?? throw new ArgumentNullException(nameof(comment));
- Description = description ?? throw new ArgumentNullException(nameof(description));
- }
- public override bool Equals(Id3Frame other)
- {
- return other is CommentFrame comment &&
- comment.Language == Language &&
- comment.Description == Description;
- }
wurde zu:
VB.NET-Quellcode
-
- Public Sub New(<NotNull> comment As String, <NotNull> description As String)
- Me.Comment = If(comment, CSharpImpl.__Throw(Of String)(New ArgumentNullException(NameOf(comment))))
- Me.Description = If(description, CSharpImpl.__Throw(Of String)(New ArgumentNullException(NameOf(description))))
- End Sub
- Public Overrides Function Equals(ByVal other As Id3Frame) As Boolean
- Dim comment As CommentFrame = Nothing
- Return CSharpImpl.__Assign(comment, TryCast(other, CommentFrame)) IsNot Nothing AndAlso comment.Language = Language AndAlso Equals(comment.Description, Description)
- End Function
- Private Class CSharpImpl
- <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
- Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
- target = value
- Return value
- End Function <Obsolete("Please refactor calling code to use normal throw statements")>
- Shared Function __Throw(Of T)(ByVal e As Exception) As T
- Throw e
- End Function
- End Class
Ich hätte das jetzt so übersetzt:
VB.NET-Quellcode
-
- Public Sub New(<NotNull> comment As String, <NotNull> description As String)
- Me.Comment = If(comment, New ArgumentNullException(NameOf(comment)))
- Me.Description = If(description, New ArgumentNullException(NameOf(description)))
- End Sub
- Public Overrides Function Equals(ByVal other As Id3Frame) As Boolean
- Dim comment As CommentFrame = TryCast(other, CommentFrame)
- Return comment IsNot Nothing AndAlso comment.Language = Language AndAlso comment.Description = Description
- End Function
Ist das so korrekt?