Macros in c#

  • Thread starter Thread starter karunakar
  • Start date Start date
K

karunakar

Hi All

I would like to use "Primaryid" instead of " Int32". how do i define it in
c#

Regards,
Venu.
 
Hi All

I would like to use "Primaryid" instead of " Int32". how do i define it in
c#

Regards,
Venu.
You can actually use the using keyword for aliasing in C#. But, it only
applies to the file it's in. So, you have to put something like this at
the top of each file:

using Primaryid = System.Int32;

HTH
 
How can we use this "using Primaryid = System.Int32;" across all the
files in all the projects ?
 
IMO, that's not really sufficient.

Defining variables as certain types is like using literal values rather than
const on a variable. You may want to change your measurements from an int to
a float for example, or a Retangle to a RectangleF... because the variables
are passed through parameters in different objects, you end up searching for
all the occurances in the code where the desired type needs to change.

How would you approach this scenario in C#?

Thanks.
Dan.
 
You could define your own struct Primaryid which contains the actual id as
int.
You also can add a implicit conversion operator to typ int.
 
How can we use this "using Primaryid = System.Int32;" across all the
files in all the projects ?

As far as I know - you can't. You have to add it manually, to each file
in the project (or write an IDE macro or addin to do it).
 
Cody nailed it. Define your own struct type that contains the type you
want as a base type, then define implicit and explicit conversion
operators as required.
 
Back
Top