我有两个Perl模块,我想将它们作为对象类型公开为C#。其中一个构造另一个类型的对象,并使用如下所示的方法返回它。我在Type1.dll中包含对Type2.dll的引用,并在C#中引用它们。如代码所示,我可以直接使用C#构造Type2对象,但无法返回由Type1中的方法构造的Type2对象。有任何想法吗?使用PerlNET将不同的perl类中的perl对象返回到C#
(从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()
的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;
的Perl:Type2.pm
package Type2;
use strict;
=for interface
[interface: pure]
static Type2();
=cut
sub new {
my $class = shift;
return bless {}, $class;
}
1;
仅供参考:我正在使用ActiveState Perl Dev Kit 8.2.1,PerlNET和.NET 3.5。 – DougWebb 2010-04-21 18:09:39
最好在你的问题中加上这个。 – Space 2010-04-26 10:20:35