RETURN different values through ExtensionMethods?

I know what Unity is but haven't used it myself. The message is saying that you are missing a cast when converting myClass to object or dynamic. So the code should look something like this in Unity.

static public object GetProperties(this myEnym input) {
    if(input<=100) return (object)myClass1;
    else return (object)myClass2;
}

And used like this

var myObject = myEnym.GetProperties();
if ((int)myEnym <= 100) {
    var myClass1 = (MyClass1)myObject;
    // Do something with myClass1
} else {
    var myClass2 = (MyClass2)myObject;
    // Do something with myClass2
}

When using the value you could check the type of the return value instead of using the value of the enum possibly like this

var myObject = myEnym.GetProperties();
if (myObject is MyClass1) {
    var myClass1 = (MyClass1)myObject;
    // Do something with myClass1
} else {
    var myClass2 = (MyClass2)myObject;
    // Do something with myClass2
}

But note that this is probably very bad code. Ideally MyClass1 and MyClass2 would have the same base class or share an interface. That way you could use something like this

static public MyBaseClass GetProperties(this myEnym input) {
    if(input<=100) return myClass1;
    else return myClass2;
}
/r/csharp Thread Parent