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

  • SEARCH
  • Home
  • 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 3306056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:14:35+00:00 2026-05-17T21:14:35+00:00

C# unfortunately does not allow for extra user-defined syntax. But I was wondering whether

  • 0

C# unfortunately does not allow for extra user-defined syntax. But I was wondering whether it was possible to surpass this limitation by tapping into the visual studio onbuild-event.

Suppose I have some syntactic sugar which could be easily translated into actual C# code.
If I were to automatically translate a cs document containing this new syntax into a valid cs document, right before a C#-project is built, then the project could build succesfully. Overall this would function as if I had extended the C# language, because I started with an invalid cs document containing unoffical syntax, but it compiled anyway.

I realize that this has a few problems, such as that this translation is permanent. This could perhaps be circumvented by restoring the original cs(which should be restored after the debugging has ended, otherwise some IDE functionality would be lost). But these are secondary problems.

Please let me know what you think of this idea. Is this possible, and if so, could someone direct me to some useful tutorials so achieve this? In specific the tapping-into-a-onbuild-event.
I’ve searched MSDN, but the topic(http://msdn.microsoft.com/en-us/library/hthab0h8.aspx) didn’t help me.

  • 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-17T21:14:36+00:00Added an answer on May 17, 2026 at 9:14 pm

    I won’t say whether this is a good idea or not, since I don’t know enough about what you’re trying to do. I would suggest this, though: What you’re proposing is to have some kind of “extended C#” source code file that gets translated into regular cs during the build process.

    Personally, I would clarify this by first breaking away from the idea that you are “extending” the C# language; I would instead think of it as defining a new language that happens to be syntactically similar to C# (I assume). Use a different file extension so that Visual Studio does not try to compile your language as C#. (Maybe .csx? People love adding the letter x, right?)

    Visual Studio already does this sort of thing in other ways that might not be quite so obvious. If you add a resource file to a project, Visual Studio will typically also include a dynamically generated “designer.cs” with code generated based on the content of your .resx file. If you look at the properties of the .resx file, you’ll note that the “Custom Tool” property has a value of “ResXFileCodeGenerator”. In theory you should be able to implement your own generator to perform the translation step that you mentioned. In fact, this translation does not have to be a one-time thing as you said. The translation process should generate a new file, but leave the original file intact. Any changes to the original file causes Visual Studio to regenerate the auto-generated file.

    I’ve not tried to implement a custom generator myself, but I think these articles are relevant: Implementing Single File Generators, and Registering Single File Generators

    Your .csproj file would contain something such as the following:

    <Content Include="Example.csx">
      <Generator>ExtendedCSharpCodeGenerator</Generator>
      <LastGenOutput>Example.cs</LastGenOutput>
    </Content>
    <Compile Include="Example.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Example.csx</DependentUpon>
    </Compile>
    

    Where Example.csx is the source code file containing your extended syntax and Example.cs is the resulting output of translating Example.csx into normal C# code.

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

Sidebar

Related Questions

I know that XSLT does not work in procedural terms, but unfortunately I have
In my application, a user has_many tickets. Unfortunately, the tickets table does not have
Our host does not allow us to modify the passenger config file (i.e. the
Unfortunately, my question is not as simple as keeping track of two windows created
Unfortunately, I need to do this. I'm using ELMAH for my error log. Before
Unfortunately, the problem is not more specific than that. I've found a few examples
Unfortunately it looks like for various reasons I'm going to have to use Visual
Unfortunately, there seems to be no string.Split(string separator), only string.Split(char speparator). I want to
Unfortunately, sometimes the only way to debug a program is by going through its
Unfortunately I don't have access to a *nix box at work or at home.

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.