Token Pasting (##)

  • Thread starter Thread starter Nelson Hsu
  • Start date Start date
N

Nelson Hsu

Is there anything like the token pasting operator (##) in C#?

I'm trying to port some unmanaged C++ code into C# and I'm not sure
how to mimic this behavior.
 
Hi,

In C++, this is a pre-processor operator, not a language operator. C#'s
pre-processor is quite minimalistic and, unfortunately, has no equivalent of
the ## operator. You can probably do the preprocessor's work yourself and
merge the tokens manually.
 
Dmitriy Lapshin said:
In C++, this is a pre-processor operator, not a language operator. C#'s
pre-processor is quite minimalistic and, unfortunately, has no equivalent of
the ## operator. You can probably do the preprocessor's work yourself and
merge the tokens manually.

I'm not sure I'd say it's unfortunate - while I haven't used token
pasting, it certainly *sounds* like the kind of thing which would make
the code hard to read. I for one am glad that the "preprocessor" in C#
is so minimal.
 
Jon,

When I said "unfortunately", I meant "unfortunately for the original poster"
as Mr. Hsu would need to do the pasting manually if he is to port the code
to C#.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 
It does make the code extremely difficult to read. The original coder
must have been on crack...or a deadline. Anyways thanks for your
guys' help! Looks like I'll have to manually do this.

Dmitriy Lapshin said:
Jon,

When I said "unfortunately", I meant "unfortunately for the original poster"
as Mr. Hsu would need to do the pasting manually if he is to port the code
to C#.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Jon Skeet said:
I'm not sure I'd say it's unfortunate - while I haven't used token
pasting, it certainly *sounds* like the kind of thing which would make
the code hard to read. I for one am glad that the "preprocessor" in C#
is so minimal.
 
token-pasting in C#

Hi All...

I have been trying to find out about implementing token-pasting operation in C#. By reading your forum, I came to know that there is no C# equivalent of token-pasting macro. From your Forum, i also came to know that it can be manually implemented.If you donot have any probelm, could plz give me some idea how it can be done. Any help is highly appreciated.


Thanku,
 
By using the parameter "[CallerMemberName] string varName = null" to add a string name variable to class constructors I get similar function to token pasting by concatenating strings to match the variable name in a SOP Btree of variable instances.
 
Back
Top