Jan Dubois'e ActiveState şirketinden bir e-posta yazdım. Bunun için geri çağırma mekanizmasını uygulamak için bir yol önerdi.
Bu yardımın umarım.
===========================================
Merhaba Minh,
PerlNET'te bir delegeyi uygulayabilirsiniz, sadece yeni delege türlerini bildiremezsiniz.
Perl'de bir temsilci tanımlayan ve daha sonra C# 'ya geçiren bazı örnek kod ekledim. Parçaları ayrı dosyalara ayırmanız ve el ile derlemeniz gerekir; Bu kod, bazı regresyon testlerinden çıkarılır ve test koşumunun geri kalanı olduğu gibi çalıştırmayacaksınız. (Biçimlendirme de biraz kırpılmış gibi görünüyor, ancak kodun amacı hala açık olmalıdır).
alkış -Jan
#!./perl -w
# Define some properties and fields in perl and try to access them.
print "1..1\n";
require 'setup.pl';
csc("-target:library DB.cs");
cleanup("DB.dll");
plc(-target => "library", -out => "P.dll", -r => "DB.dll", "P.pm");
csc("test.cs -r:DB.dll -r:P.dll");
cleanup("./test.exe");
my $res = `./test.exe`;
print "----\n$res----\n";
print "not " unless $res eq <<'EOT';
XXX 65
XXX 66
XXX 67
XXX 68
XXX 69
XXX 70
XXX 71
XXX 4.2
XXX 4.30000019073486
XXX 4.4
XXX a
XXX 1
XXX ""
XXX Hi
XXX <undef>
EOT
print "ok 1\n";
__END__
======================= Test.cs ===== ================
using System;
class main : IPrint
{
public static void Main(string[] args)
{
P p = new P(new main());
DataBase db = new DataBase();
db.Add((byte)65);
db.Add((short)66);
db.Add((int)67);
db.Add((long)68);
db.Add((uint)69);
db.Add((ushort)70);
db.Add((ulong)71);
db.Add(4.2D);
db.Add(4.3F);
db.Add(4.4M);
db.Add('a');
db.Add(true);
db.Add(false);
db.Add("Hi");
db.Add(null);
db.Scan(p.handler);
}
main() {}
public void print(string s) {
Console.WriteLine(s);
}
}
======================= DB.cs =
,
package P;
=for interface
interface ProcessItem; # a delegate type
interface IPrint;
interface System.Object;
interface P {
static P P(IPrint ip);
readonly ProcessItem handler;
void x(System.Object y);
private field IPrint ip;
}
=cut
sub P {
my($self, $ip) = @_;
$self->{ip} = $ip;
}
sub handler {
my $self = shift;
return ProcessItem->new($self, "x");
}
sub x {
my($self, $obj) = @_;
$obj = "<undef>" unless defined $obj;
$obj = '""' unless length $obj;
$self->{ip}->print("XXX $obj");
}
1;