我有两个Perl模块,我想将它们作为对象类型公开给C#.其中一个构造另一个类型的对象,并使用如下所示的方法返回它.我在Type1.dll中包含对Type2.dll的引用,并在C#中引用它们.如代码所示,我可以直接从C#构造一个Type2对象,但是我不能返回由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()
Run Code Online (Sandbox Code Playgroud)
Perl: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;
Run Code Online (Sandbox Code Playgroud)
Perl:Type2.pm
package …
Run Code Online (Sandbox Code Playgroud)