ジェネリック クラスがある場合:
class Collection < G > {
public G[] stuff
}
他に 2 つのクラスがあり、そのうちの 1 つはもう 1 つのクラスに変換できます (ただし、これよりも複雑です!)
class Foo {
public Foo( int i ) { myInt = i; }
public int myInt;
}
class Bar {
public Bar( float f ) { myFloat = f; }
public float myFloat;
public static implicit operator Foo( Bar bar ) {
return new Foo( Math.Ceil(bar.myFloat) );
}
}
そして、私は両方のコレクションを持っています:
Collection < G > fooCollection = new Collection < Foo > ();
Collection < G > barCollection = new Collection < Bar > ();
私はこのようなことができるようにしたい:
Collection < G > fooCollection2 = barCollection.Convert( typeof(Foo) );
どうすればそれについて行くでしょうか?
編集: これは Unity 用です。Unity はまだ .NET 2.0 にあると思います。