Skip to content

Instantly share code, notes, and snippets.

@alekseytimoshchenko
Created July 30, 2020 08:34
Show Gist options
  • Save alekseytimoshchenko/48162c8b5d1747e9050db0c3be201aa1 to your computer and use it in GitHub Desktop.
Save alekseytimoshchenko/48162c8b5d1747e9050db0c3be201aa1 to your computer and use it in GitHub Desktop.
class MyMain
{
private MyFirstEnum myType = MyFirstEnum.DOCUMENT; //Type that I know according to my object
public void Boo()
{
//Here I need to create new Foo obeject that get
//MySecondEnum as a param, but this MySecondEnum is not compatible with MyFirstEnum
//what I need to do here?
//Solotion is:
//Create new MyFirstEnum type and compare it with type that I know - myType class member(in our case)
MySecondEnum myNeededType = MySecondEnum.DEFAULT;
if(myType == MyFirstEnum.DOCUMENT)
{
myNeededType = MySecondEnum.DOCUMENT; //Now I know my needed type. Other words I compare my type that I know to type that I need.
}
//For now I am ready to create object that I need
Foo myObject = new Foo(myNeededType); //TA-DA :)
}
}
class Foo
{
public Foo(MySecondEnum type)
{
}
}
enum MyFirstEnum // My first type
{
DEFAULT,
DOCUMENT,
FOLDER
}
enum MySecondEnum // My second type
{
DEFAULT,
DOCUMENT,
FOLDER
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment