0

I want to write simple macro in c#, to be more clear i just want to save some typing when testing (but want use snippets, cause they don't save space). Want to replace reserved keywords with shorter words Example in c++ (return sum):

#define r return
int foo(int i, int c){ r (i + c); }

So the point is to save same space and typing, is there something similar in c#?

tonni
  • 1,225
  • 4
  • 19
  • 35
  • If you're using Visual Studio, try typing "re" and then hit Tab. It'll save you typing (but not space). – Matthew Watson Feb 28 '14 at 09:02
  • Also i need to save some space ... – tonni Feb 28 '14 at 09:04
  • possible duplicate of [C# Macro definitions in Preprocessor](http://stackoverflow.com/questions/709463/c-sharp-macro-definitions-in-preprocessor) – sloth Feb 28 '14 at 09:06
  • No it's not possible duplicate this is different question with different needs – tonni Feb 28 '14 at 09:10
  • @tonni How is it any different? Just because you talk about `return` and not about `Console.WriteLine`? – sloth Feb 28 '14 at 09:12
  • Could you elaborate on why you need to save space? All I see is that you are making your code unreadable => not maintainable. As mentioned earlier: to save typing IntelliSense and snippets were invented. – MarkO Feb 28 '14 at 09:14
  • I already say that for testing (app testing), in this scenario code readable is out of focus. – tonni Feb 28 '14 at 09:16
  • If code doesn't need to be readable then the clear implication is that it is auto-generated and not going to be read by a human - in which case you don't care how short it is. But if you tell me that it *is* going to be read by a human, then I'm going to tell you that it should be readable. – Matthew Watson Feb 28 '14 at 09:33

1 Answers1

3

C# does not support macros like C++. Visual Studio on the other hand has snippets

Check that question:

C# Macro definitions in Preprocessor

Macros in a different sense:

http://alookonthecode.blogspot.com.au/2011/06/macros-in-c.html

A Macro Preprocessor in C#

http://www.codeproject.com/Articles/10049/A-Macro-Preprocessor-in-C

Community
  • 1
  • 1
Rami
  • 7,162
  • 1
  • 22
  • 19
  • Snippet have to be written outside of code .... i want to do it in code with something like dictionary or else – tonni Feb 28 '14 at 09:03
  • thnx for effort but this don't change reserved keyword it is something like refactory – tonni Feb 28 '14 at 09:14
  • 1
    In that case you need to write your own preprosessor. Check that codeproject article http://www.codeproject.com/Articles/10049/A-Macro-Preprocessor-in-C – Rami Feb 28 '14 at 09:16