Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export part of the namespace of a class

I have a class that includes an enum:

class appearance{
  // ... stuff ...
  enum color {BLUE, RED, GREEN};
};

I would like to attach part of the namespace (with using) so that I can refer to the value of the BLUE simply as BLUE, rather than appearance::BLUE. At the same time, I would like to keep the enum within the class{}, since I think that is most natural. I have tried various combinations of namespace and using, but to no avail.

Any suggestions ???

like image 816
nullglob Avatar asked Oct 13 '10 15:10

nullglob


People also ask

What is export as namespace?

The export as namespace form creates a global variable so it can be used without importing, but you may still import it with the import { name } from "some-library" form of import.

What is the use of namespace in TypeScript?

The namespace is used for logical grouping of functionalities. A namespace can include interfaces, classes, functions and variables to support a single or a group of related functionalities. A namespace can be created using the namespace keyword followed by the namespace name.

Can a namespace have the same name as a class?

Inside a namespace, no two classes can have the same name.

How do you call a namespace in TypeScript?

Namespace Declaration We can declare the namespace as below. To access the interfaces, classes, functions, and variables in another namespace, we can use the following syntax. If the namespace is in separate TypeScript file, then it must be referenced by using triple-slash (///) reference syntax.


1 Answers

I don't think it can be done. AFAIK, you can use using appearance::color in another class or structure as stipulated here.

A using declaration in a class A may name one of the following:

  • A member of a base class of A

  • A member of an anonymous union that is a member of a base class of A

  • An enumerator for an enumeration type that is a member of a base class of A

like image 167
Jacob Avatar answered Sep 21 '22 15:09

Jacob