Project

General

Profile

root / branches / compiler / cSharp / ooasCompiler / src / libs / c5 / UserGuideExamples / ThisFun.cs @ 3

1
// Experiment: implicit conversion of indexer to function
2
// sestoft@dina.kvl.dk * 2005-11-08
3

    
4
using System;
5
using C5;
6

    
7
class MyFunTest {
8
  public static void Main(String[] args) {
9
    FooBar fb = new FooBar();
10
    IList<int> list = new LinkedList<int>();
11
    list.AddAll(new int[] { 2, 3, 5, 7, 11 });
12
    list.Map<double>(fb).Apply(Console.WriteLine);
13
    list.Apply(fb);
14
  }
15
}
16

    
17
class FooBar {
18
  public double this[int x] { 
19
    get { 
20
      Console.WriteLine(x); 
21
      return x + 1.5; 
22
    } 
23
  }
24

    
25
  public Fun<int,double> Fun {
26
    get { 
27
      return delegate(int x) { return this[x]; };
28
    }
29
  }
30

    
31
  public Act<int> Act {
32
    get { 
33
      return delegate(int x) { double junk = this[x]; };
34
    }
35
  }
36
  
37
  public static implicit operator Fun<int,double>(FooBar fb) {
38
    return delegate(int x) { return fb[x]; };
39
  }  
40

    
41
  public static implicit operator Act<int>(FooBar fb) {
42
    return delegate(int x) { double junk = fb[x]; };
43
  }  
44
}
45

    
46