summaryrefslogtreecommitdiff
path: root/tests/src/Loader/classloader/DefaultInterfaceMethods/sharedgenerics/sharedgenerics.cs
blob: 93b214dfb7d4a66da317869dd9830a8e2bc5bc48 (plain)
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
using System;

interface IFoo<T>
{
    Type Foo(T a);
}

interface IBar<in T>
{
    Type Bar(T b);
}

class FooBar<T, U> : IFoo<T>, IBar<U>
{
    public Type Foo(T a)
    {
        Console.WriteLine("At IFoo.Foo:Arg={0}, TypeOf(T)={1}", a.ToString(), typeof(T));
        return typeof(T);            
    }

    public Type Bar(U b)
    {
        Console.WriteLine("At IBar.Bar:Arg={0}, TypeOf(T)={1}", b.ToString(), typeof(U));
        return typeof(U);
    }
}

class Program
{
    public static int Main()
    {
        FooBar<string, object> fooBar = new FooBar<string, object>();
        IFoo<string> foo = (IFoo<string>) fooBar;
        IBar<string[]> bar = (IBar<string[]>) fooBar;

        Console.WriteLine("Calling IFoo<string>.Foo on FooBar<string, object> - expecting default method IFoo<string>.Foo");
        Test.Assert(foo.Foo("ABC") == typeof(string), "Calling IFoo<string>.Foo on FooBar<string, object>");

        Console.WriteLine("Calling IBar<string[]>.Foo on FooBar<string, object> - expecting default method IBar<object>.Foo");
        Test.Assert(bar.Bar(new string[] { "ABC" }) == typeof(object), "Calling IBar<object>.Bar on FooBar<string, object>");

        return Test.Ret();
    }
}

class Test
{
    private static bool Pass = true;

    public static int Ret()
    {
        return Pass? 100 : 101;
    }

    public static void Assert(bool cond, string msg)
    {
        if (cond)
        {
            Console.WriteLine("PASS");
        }
        else
        {
            Console.WriteLine("FAIL: " + msg);
            Pass = false;
        }
    }
}