Inheriting Enums...
-
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!
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
-
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!
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
-
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
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. -
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.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
-
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
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? -
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?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
-
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
-
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
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;
-
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;
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
-
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
-
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;