Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:29:52+00:00 2026-05-30T17:29:52+00:00

I recently found myself using the same pattern over and over in my code.

  • 0

I recently found myself using the same pattern over and over in my code. Basically it is a variation of visitor pattern that I use to resolve references to instances of base classes to derived ones. This approach requires lots of boilerplate code.

The questions:

  • How do I multi-dispatch a method in C# in a static/strictly-typed manner without writing tons of visitors code?
  • Is there a tool/extension that generates this code?
  • Why there is nothing in C# language that addresses multi-dispatching? I don’t believe I am the only one who finds this annoying. I might be awfully wrong and the problem doesn’t exists, so I would like to know how you go along with it.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:29:53+00:00Added an answer on May 30, 2026 at 5:29 pm

    How to multi-dispatch a method in C# in a static/strictly-typed way without writing tons of visitors code?

    I’m not aware of any technique for that.

    In the Roslyn version of the C# compiler, which is written in C#, we use the visitor pattern all over the place, on type hierarchies that have dozens or hundreds of members. We have written a utility that converts an XML description of the types into the declarations of the types along with base classes for the visitors. That seems to work quite well for us.

    Is there a tool/extension that generates this code?

    There is; we wrote it ourselves. It wasn’t hard. You can do the same.

    Why doesn’t C#, as a language, have anything to address multi-dispatch issue?

    We have a list of possible language features literally longer than your arm. Any given release we have the budget to do two or three of them, tops, and therefore we concentrate on getting the most possible bang for the buck.

    Making it easier to implement double (or multiple) virtual dispatch via auto-generating the visitor pattern has never made it anywhere near to the top of that list. There are literally dozens of other possible patterns that we could be embedding in the language that are more “bang for the buck”. If you do a survey of popular languages you will find that very few languages support double or multiple virtual dispatch via static analysis, and the ones that do are not hugely popular. There’s a reason for that: first, because it’s not actually a very useful feature, and second, because when you do need it, you can achieve it by implementing the pattern yourself, or by using dynamic dispatch.

    As you note, there are significant drawbacks to both the pattern-based approach and the dynamic dispatch approach. But, though there are drawbacks, they are both feasible for ordinary line-of-business developers to implement themselves should they need to. When evaluating which patterns to embed in the language, we lean towards those patterns that are really quite difficult for ordinary developers to implement themselves using a pattern-based approach. The visitor pattern is not difficult; it’s just verbose.

    For example: In C# 2 we chose to embed the “sequence generator” pattern in the language. In C# 3 we chose to embed the “query comprehensions with sequence monads” pattern in the language. In C# 4 we chose to embed the “dynamic dispatch” pattern in the language. In C# 5 we chose to embed the “pass the current continuation as a delegate” pattern into the language. All of these are examples of big “bang for buck” — they were expensive features to implement, but they fundamentally make new styles of programming available in the core language.

    There’s only a finite amount of effort available in any release; embedding one pattern in the language in a release prevents us from embedding any other pattern in the language in that release because there simply isn’t the budget to do it.

    When embedding the “double (or multiple) virtual dispatch” pattern into the language becomes the best possible way to spend our budget, we’ll do it, and not before. You should therefore expect a long wait.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently found myself writing a piece of code that executed a Core Data
Recently I have found myself using StringBuilder for all string concatenations, big and small,
I've found myself having to write some VBA code recently and just wondered if
Recently I've found myself testing an aplication in Froglogic's Squish, using Python to create
I have recently found myself becoming more negative about EF and cannot help wondering
Recently, I found myself having to write up some concerns I have about race
I recently found a log statement in my projects codebase that says here i
I recently found LINQ and love it. I find lots of occasions where use
I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2
Recently i've found myself writing a lot of methods with what i can only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.