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.
In the Disk Management window, right-click on the C drive and select "Shrink Volume". This will open a new window where you can enter the amount of space you want to free up. Next, right-click on the other drives and select "Expand Volume". This will add the freed up space to the other drives.
Conclusion: You Can Extend SSD C Drive to Another Disk Like an Expert with A Powerful Tool.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With