オブジェクト型として C# に公開したい 2 つの Perl モジュールがあります。それらの 1 つは、他の型のオブジェクトを構築し、以下に示すメソッドを使用してそれを返します。Type1.dll に Type2.dll への参照を含め、C# で両方を参照しています。コードが示すように、Type2 オブジェクトを C# から直接作成できますが、Type1 のメソッドによって作成された Type2 オブジェクトを返すことはできません。何か案は?
(これはhttp://community.activestate.com/forum/return-perl-object-different-perl-class-cから相互投稿されています。)
C#:
Type1 obj1 = new Type1(); // Works
Type2 test = new Type2(); // Works
Type2 obj2 = obj1.make2();
// Fails: System.InvalidCastException: Unable to cast object of type
// 'PerlRunTime.SV' to type 'Type2' at Type1.make2()
パール:Type1.pm
package Type1;
use strict;
use Type2;
=for interface
[interface: pure]
static Type1();
Type2 make2();
=cut
sub new {
my $class = shift;
return bless {}, $class;
}
sub make2 {
my $this = shift;
return Type2->new();
}
1;
パール:Type2.pm
package Type2;
use strict;
=for interface
[interface: pure]
static Type2();
=cut
sub new {
my $class = shift;
return bless {}, $class;
}
1;