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. Inheriting Enums...

Inheriting Enums...

Scheduled Pinned Locked Moved C#
question
12 Posts 4 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.
  • D devzav

    Hi all! I'm new in object programming and I have a question for you. I have a class (Class1) that uses an Enum type called EType. I created another class (Class2) that wrap the first class. So I can use that Enum in Class2 by referencing the first class. Now I made a windows application that references Class2 and should use that Enum EType. Is there a way to catch EType from the Class2, or have I to reference the Class1 too? Thank you very much in advantage!

    P Offline
    P Offline
    pmarfleet
    wrote on last edited by
    #3

    devzav wrote:

    I created another class (Class2) that wrap the first class.

    What do you mean by 'wrap'? Does Class2 inherit from Class1? Please try and use the proper terminology when posting questions, otherwise no one will understand what you are talking about. If you are using inheritance and your enum in Class1 is a public member of this class, you should be able to access it as a member of Class2 from a class that references Class2.

    Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

    1 Reply Last reply
    0
    • T TJoe

      Your question doesn't make sense, can you please rephrase it. And maybe include some code samples.

      Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

      D Offline
      D Offline
      devzav
      wrote on last edited by
      #4

      Sure! I beg your perdon for my poor English... I'll try again :P I have a project A like this: namespace A { public enum EType : int { a, b, c } public class Class1 { ... } } Then I made a project B that references the project above, so that I can use A.EType as type in my project B. Now I need to use the EType type in another project, the C project that should have the project B as only reference. How can I catch EType from the B project? Thank you.

      T 1 Reply Last reply
      0
      • D devzav

        Sure! I beg your perdon for my poor English... I'll try again :P I have a project A like this: namespace A { public enum EType : int { a, b, c } public class Class1 { ... } } Then I made a project B that references the project above, so that I can use A.EType as type in my project B. Now I need to use the EType type in another project, the C project that should have the project B as only reference. How can I catch EType from the B project? Thank you.

        T Offline
        T Offline
        TJoe
        wrote on last edited by
        #5

        In short, you won't be able to get EType from project B, because it's in project A. If B -> A and C -> B, then why can't C -> A? Project A is going to be required for C to run anyway, if it references B (because B requires A). You could create a new enum type in B that derives from EType (as your forum post suggests), but you will still need a reference to A in C (because it will need to know the inherited enumerations).

        Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

        D 1 Reply Last reply
        0
        • T TJoe

          In short, you won't be able to get EType from project B, because it's in project A. If B -> A and C -> B, then why can't C -> A? Project A is going to be required for C to run anyway, if it references B (because B requires A). You could create a new enum type in B that derives from EType (as your forum post suggests), but you will still need a reference to A in C (because it will need to know the inherited enumerations).

          Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

          D Offline
          D Offline
          devzav
          wrote on last edited by
          #6

          Thank you very much for your fast reply! So if B has the ClassB with a method like this: public class ClassB { ... public void MethodB(A.EType myType) { ... } } and I call it in projectC in this way: B.ClassB bClass = new B.ClassB(); bClass.MethodB(myNewType); have I to define necessary myNewType as A.EType (and so I have to reference the projectA in my projectC), or is there a trick to avoid it?

          T 1 Reply Last reply
          0
          • D devzav

            Thank you very much for your fast reply! So if B has the ClassB with a method like this: public class ClassB { ... public void MethodB(A.EType myType) { ... } } and I call it in projectC in this way: B.ClassB bClass = new B.ClassB(); bClass.MethodB(myNewType); have I to define necessary myNewType as A.EType (and so I have to reference the projectA in my projectC), or is there a trick to avoid it?

            T Offline
            T Offline
            TJoe
            wrote on last edited by
            #7

            No, you'll have to reference A. Keep in mind that A would be required to load and use B anyway. So if C references B, then you would need to ship A, B, and C in order to use C.

            Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

            D 1 Reply Last reply
            0
            • T TJoe

              No, you'll have to reference A. Keep in mind that A would be required to load and use B anyway. So if C references B, then you would need to ship A, B, and C in order to use C.

              Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

              D Offline
              D Offline
              devzav
              wrote on last edited by
              #8

              Thank you, Tom :)

              1 Reply Last reply
              0
              • T TJoe

                Your question doesn't make sense, can you please rephrase it. And maybe include some code samples.

                Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

                Y Offline
                Y Offline
                YouMiss
                wrote on last edited by
                #9

                Errr... I only supposed that I partially understand your question. But, after referred to others' posts, I guess what you were trying to do was merely certain issues of "namespace" that you misunderstood. In general, a .NET namespace provides a way to encapsulate your classes, delegates, structures, enumerations etc. Meaning, anything you create or implement ought to ultimately exist in namespaces. In such a manner, a project doesn't really suggest an individual object which you can reference to; it merely groups whatever namespaces needed and manipulate the members existing in a pre-defined sequence. Thus, for your question, you define a public enumeration in project A which subsequently defines "namespace A"; in order to make use of the enumeration, you have to reference the "namespace A" in whatever post projects you create. Hope it's helpful. Ray -- modified at 22:51 Thursday 15th November, 2007 -- modified at 22:52 Thursday 15th November, 2007

                Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;

                T D 2 Replies Last reply
                0
                • Y YouMiss

                  Errr... I only supposed that I partially understand your question. But, after referred to others' posts, I guess what you were trying to do was merely certain issues of "namespace" that you misunderstood. In general, a .NET namespace provides a way to encapsulate your classes, delegates, structures, enumerations etc. Meaning, anything you create or implement ought to ultimately exist in namespaces. In such a manner, a project doesn't really suggest an individual object which you can reference to; it merely groups whatever namespaces needed and manipulate the members existing in a pre-defined sequence. Thus, for your question, you define a public enumeration in project A which subsequently defines "namespace A"; in order to make use of the enumeration, you have to reference the "namespace A" in whatever post projects you create. Hope it's helpful. Ray -- modified at 22:51 Thursday 15th November, 2007 -- modified at 22:52 Thursday 15th November, 2007

                  Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;

                  T Offline
                  T Offline
                  TJoe
                  wrote on last edited by
                  #10

                  You may want to reply to devzav, so he gets notified of your reply.

                  Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

                  Y 1 Reply Last reply
                  0
                  • T TJoe

                    You may want to reply to devzav, so he gets notified of your reply.

                    Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

                    Y Offline
                    Y Offline
                    YouMiss
                    wrote on last edited by
                    #11

                    Surely. Hee, Hee.

                    Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;

                    1 Reply Last reply
                    0
                    • Y YouMiss

                      Errr... I only supposed that I partially understand your question. But, after referred to others' posts, I guess what you were trying to do was merely certain issues of "namespace" that you misunderstood. In general, a .NET namespace provides a way to encapsulate your classes, delegates, structures, enumerations etc. Meaning, anything you create or implement ought to ultimately exist in namespaces. In such a manner, a project doesn't really suggest an individual object which you can reference to; it merely groups whatever namespaces needed and manipulate the members existing in a pre-defined sequence. Thus, for your question, you define a public enumeration in project A which subsequently defines "namespace A"; in order to make use of the enumeration, you have to reference the "namespace A" in whatever post projects you create. Hope it's helpful. Ray -- modified at 22:51 Thursday 15th November, 2007 -- modified at 22:52 Thursday 15th November, 2007

                      Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;

                      D Offline
                      D Offline
                      devzav
                      wrote on last edited by
                      #12

                      Thank you for your answer :)

                      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