Token Pasting (##)

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.
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 
J

Jon Skeet [C# MVP]

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.
 
D

Dmitriy Lapshin [C# / .NET MVP]

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
 
N

Nelson Hsu

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.
 
Joined
Dec 5, 2005
Messages
1
Reaction score
0
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,
 
Joined
Dec 18, 2013
Messages
1
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top