Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

#define equivalent in C#

I've got a program here I'm writing in C#.  It accesses an automatically generated COM component for communication to a target processor.

Now, the automatically generated COM component has the name of the application it was generated from in various places.  The filename it generates is (given a source file of "foorbar" ) foobarCOMIFACE.DLL, and the objects it generates are called foobarbio and foobarpt.

Now, the source file that I'm generating this from has changed the name in the past, and I'd like to be able to change the name of this file with a minimum of find/replace. 

In C++, I'd play games with the preprocessor so I could just change the "foobar" in one statement and have (for example) the #import and interface declaration macroed together. 

How would I do this in C#?

Alex
Friday, July 02, 2004

You can't. C# has no macro preprocessor. There's a #define statement but its label can only be checked by #if directives for conditional compilation, you can't inject them into code.

If you only need the changing name in strings you could use a const string, of course. But that won't work for interface or class names.

You could use CodeSmith if you need a "big" template solution but that's overkill for a single name. I suggest the trusty search & replace command.

Chris Nahr
Saturday, July 03, 2004

Or, you could use reflection to access the Properties / classes.

Koz
Saturday, July 03, 2004

You can alias types using the 'using' directive

e.g.

using ReliableTypeName = VolatileNamespace.VolatileTypeName;

Rick
Friday, July 23, 2004

First of all, C++ does not have any #import  epxressions(java term) in it. The C# equivalent -as pathetic as it is-is "using. "

#include io.h;

VJ ++

import java.awt;


and to create an object which inherits correctly in C++, as C# has to, is

Class.oject

Cdialog:MyNewDailogClassNameIsFuckingJoke()

MyNewDialogClassNameIsAFuckingJoke.OpenUpAndSayAwwWeCanBeVeryMoronic.

An farcical example, bu reflects the obervable times.

Back - dot - of- the- bus-!

Master of the universe
Friday, August 06, 2004

*  Recent Topics

*  Fog Creek Home