public interface ifX {}
public struct X : ifX { public string myName; }
public struct Y : ifX { public string myName; }
public struct Z : ifX { public string myName; }
// "Two" throws:
public static Action<ifX>[] cc = {
One,
Two, // Compiler error: Expected a method with 'void Two(ifX)' signature
_x => Three((Z)_x) // Its a solution. But is it performant
};
// Currently:
static void One(ifX item1)
{
var myItem = (X)item1;
Debug.Log(myItem.myName);
}
// Preferably:
static void Two(Y item2)
{
Debug.Log(item2.myName);
}
// Dirty walkaround (see in declaration)
static void Three(Z item2)
{
Debug.Log(item2.myName);
}
static void DoStuff()
{
var xItem = new X();
cc[0].Invoke(xItem);
var yItem = new Y();
cc[1].Invoke(yItem);
var zItem = new Z();
cc[2].Invoke(zItem);
}
Above is an oversimplified demo of what I’m trying to accomplish. Currently the standard way would be invocation of One(ifX)
, preferably I would invoke it as Two(Y)
, there is a workaround at _x => Three((Z)_x)
but I think performance will be terrible is there a better way, and if not, how performant is that particular solution?