1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| using System;
using System.Collections.Generic;
using System.Linq;
namespace TypeVisiting
{
class Foo
{
public string Bar { get; set; }
public int Baz { get; set; }
}
class Bar
{
public List<string> Values { get; set; }
}
class Baz
{
public List<Foo> Foos { get; set; }
}
class Qux
{
public List<Baz> Bazes { get; set; }
}
class Program
{
static void Main ()
{
var in1 = "abcd";
var out1 = Transform<string, string> (in1, s => s.Replace ("b", "B"));
var in2 = new Foo {
Bar = "abcd",
Baz = 1
};
var out2_1 = Transform<Foo, string> (in2, s => s.Replace ("b", "B"));
var out2_2 = Transform<Foo, int> (in2, n => n * 2);
var in3 = new Bar {
Values = new List<string> {
"abcd",
"bcde"
}
};
var out3 = Transform<Bar, string> (in3, s => s.Replace ("b", "B"));
var in4 = new Baz {
Foos = new List<Foo> {
new Foo {
Bar = "abcd", Baz = 1
},
new Foo {
Bar = "bcde",
Baz = 2
}
}
};
var out4_1 = Transform<Baz, string> (in4, s => s.Replace ("b", "B"));
var out4_2 = Transform<Baz, int> (in4, n => n * 2);
var in5 = new Qux {
Bazes = new List<Baz> {
new Baz {
Foos = new List<Foo> {
new Foo {
Bar = "abcd",
Baz = 1
},
new Foo {
Bar = "bcde",
Baz = 2
}
}
},
new Baz {
Foos = new List<Foo> {
new Foo {
Bar = "dcba",
Baz = 3
},
new Foo {
Bar = "edcb",
Baz = 4
}
}
}
}
};
var out5_1 = Transform<Qux, string> (in5, s => s.Replace ("b", "B"));
var out5_2 = Transform<Qux, int> (in5, n => n * 2);
} |
Partager