Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. can we do alias in namespace?

can we do alias in namespace?

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I meet such a situation that there is hundreds of classes in a big namespace, and i just want to borrow something from it. i write something like this: ===================================== namespace big { class apple; class banana; ... } ===================================== namespace small { class apple: big.apple { } } ===================================== But i hope not to use inherit. is there any way to declare a alias or mapping?

    J 1 Reply Last reply
    0
    • L Lost User

      I meet such a situation that there is hundreds of classes in a big namespace, and i just want to borrow something from it. i write something like this: ===================================== namespace big { class apple; class banana; ... } ===================================== namespace small { class apple: big.apple { } } ===================================== But i hope not to use inherit. is there any way to declare a alias or mapping?

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      If you mean, give a new name to an existing object; then yes you can do that. using apple = big.apple; This only works on a file by file basis though. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

      L 1 Reply Last reply
      0
      • J James T Johnson

        If you mean, give a new name to an existing object; then yes you can do that. using apple = big.apple; This only works on a file by file basis though. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thank you. But what i exactly want is something like the cpp's #define. #define small.apple big.apple And pick the defines in a single header file, then it will only expose small part of a big library to user. BTW, when i transfer my former cpp code to C#, i find it difficult to do with the #define macro. for example #define AT_LEAST(A,B) ... here A B can be int, float, or double (surely template is another choice). But in C#, #define can only define a symbol served for selected compile. any suggestion?

        J 1 Reply Last reply
        0
        • L Lost User

          Thank you. But what i exactly want is something like the cpp's #define. #define small.apple big.apple And pick the defines in a single header file, then it will only expose small part of a big library to user. BTW, when i transfer my former cpp code to C#, i find it difficult to do with the #define macro. for example #define AT_LEAST(A,B) ... here A B can be int, float, or double (surely template is another choice). But in C#, #define can only define a symbol served for selected compile. any suggestion?

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          nova chen wrote: And pick the defines in a single header file, then it will only expose small part of a big library to user. Nope, for that you'll have to create empty wrappers as you had mentioned in the first post. nova chen wrote: But in C#, #define can only define a symbol served for selected compile. This is because #define's aren't type safe, and .NET is extremely type-safe; which is why they took out the ability to use macros in code. In most cases whenever you used a macro you should use a function instead. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups