// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; public static class Generics { public class MyArray { public class NestedClass { public T Item1; public Y Item2; } private T[] arr; public MyArray(int capacity) { this.arr = new T[capacity]; } public void Size(int capacity) { Array.Resize(ref this.arr, capacity); } public void Grow(int capacity) { if (capacity >= this.arr.Length) { this.Size(capacity); } } } public interface IInterface { void Method1() where T : class; void Method2() where T : class; } public abstract class Base : Generics.IInterface { // constraints must be repeated on implicit interface implementation public abstract void Method1() where T : class; // constraints must not be specified on explicit interface implementation void Generics.IInterface.Method2() { } } public class Derived : Generics.Base { // constraints are inherited automatically and must not be specified public override void Method1() { } } private static Type type1 = typeof(List<>); private static Type type2 = typeof(Generics.MyArray<>); private static Type type3 = typeof(List<>.Enumerator); private static Type type4 = typeof(Generics.MyArray<>.NestedClass<>); private static Type type5 = typeof(List[]); public static void MethodWithConstraint() where T : class, S where S : ICloneable, new() { } public static void MethodWithStructConstraint() where T : struct { } public static Dictionary.KeyCollection.Enumerator GetEnumerator(Dictionary d, Generics.MyArray.NestedClass nc) { // Tests references to inner classes in generic classes return d.Keys.GetEnumerator(); } }