// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // using System; public interface IFoo { Type InterfaceMethod(); } public class FooClass : IFoo { public Type InterfaceMethod() { return this.GetType(); } } public struct FooStruct : IFoo { public Type InterfaceMethod() { return this.GetType(); } } public class GenClass where T : IFoo { public bool CallOnConstraint(T t) { return (t.InterfaceMethod().Equals(typeof(T))); } public virtual bool VirtCallOnConstraint(T t) { return (t.InterfaceMethod().Equals(typeof(T))); } } public struct GenStruct where T : IFoo { public bool CallOnConstraint(T t) { return (t.InterfaceMethod().Equals(typeof(T))); } } public class Test { public static int counter = 0; public static bool result = true; public static void Eval(bool exp) { counter++; if (!exp) { result = exp; Console.WriteLine("Test Failed at location: " + counter); } } public static int Main() { Eval(new GenClass().CallOnConstraint(new FooClass())); Eval(new GenClass().CallOnConstraint(new FooStruct())); Eval(new GenClass().VirtCallOnConstraint(new FooClass())); Eval(new GenClass().VirtCallOnConstraint(new FooStruct())); Eval(new GenStruct().CallOnConstraint(new FooClass())); Eval(new GenStruct().CallOnConstraint(new FooStruct())); if (result) { Console.WriteLine("Test Passed"); return 100; } else { Console.WriteLine("Test Failed"); return 1; } } }