Req14: Non-empty default partial methods

[This post is part of a series, "wish-list for future versions of VB"]


IDEA: Allow a non-empty default partial method. (This suggestion from Bill McCarthy). For instance,

Partial Class C

    Partial Private Sub f(ByVal s As String)

        Console.WriteLine("default body - {0}", s)

    End Sub

End Class


Partial Class C

    Private Sub f(ByVal s As String)

        Console.WriteLine("user provides a body")

        Partial("and can also call the default body if desired")

    End Sub

End Class


Provisional evaluation from VB team: Seems an okay idea, but niche, and confusing. Does anyone have scenarios where this would be useful?

Comments (4)

  1. Kevin Ryall says:

    I can’t think of a good use for this…

  2. Andrés Villanueva says:

    Brilliant. Think code generation.

    Partial classes changed the way we do code generation. Before, we generated base classes and a derived (usually empty) class that inherited that one. This way, you could override methods or properties.

    With the introduction of partial classes, this changed drastically, but we always missed the ability to "override" a method. This way, you could declare all those previously overridable methods as partial and get the same behavior.

  3. Héctor says:

    While reading this, I thought of the Dispose method that the designer adds to forms, usercontrols, etc heh.

  4. tobi says:

    Linq2SQL does its code generation this way in C#.

Skip to main content