继承C#到VB的位置

bat*_*aci 1 c# vb.net c#-to-vb.net

有人可以解释一下下面这个功能的含义吗?对不起,我是VB开发人员,我无法理解下面的语法.转换器工具将其无意义地转换为VB代码.

  • 我不明白T的用法
  • 我不理解Where T的继承

     public static string ValidateSeName<T>(this T entity, string seName, string name, bool ensureNotEmpty)
             where T : BaseEntity, ISlugSupported
    {
    }
    
    Run Code Online (Sandbox Code Playgroud)

调用此函数的位置,调用函数如下所示.这个T实体的第一个参数发生了什么,它不用作参数?它的目的是什么?

  model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
Run Code Online (Sandbox Code Playgroud)

如果你能在VB中给我相同的代码,将会很有帮助.谢谢

Tim*_*ter 6

这是一个通用的扩展方法,VB.NET也支持它:

Public Module MyExtensionMethods

    <System.Runtime.CompilerServices.Extension()> _
    Public Function ValidateSeName(Of T As { BaseEntity, ISlugSupported })(entity As T, seName As String, name As String, ensureNotEmpty As Boolean) As String

    End Function

End Module
Run Code Online (Sandbox Code Playgroud)

where(在C#中)或与As(在VB.NET中)中定义的约束与继承无关.它只是告诉编译器只允许这些类型T.