All pastes #1215578 Raw Edit

Someone

public text v1 · immutable
#1215578 ·published 2008-10-01 08:21 UTC
rendered paste body
using System;

namespace Martin.Baulig
{
	public class X
	{
		public int A;
	}

	public class Y
	{
		public int B;
	}

	public struct SomeStruct<R>
	{
		public int A;
		public R Data;

		public SomeStruct (int a, R data)
		{
			this.A = a;
			this.Data = data;
		}

		public override string ToString ()
		{
			return String.Format ("SomeStruct ({0}:{1})", A, Data);
		}
	}

	public class Test<S>
		where S : new ()
	{
		public S Data;

		public Test ()
		{
			this.Data = new S ();
		}

		public void Hello ()
		{
			Console.WriteLine (Data);
		}
	}

	public class Foo<T>
		where T : new ()
	{
		public readonly T Data;
		public readonly Test<T> Test;

		public Foo ()
		{
			Data = new T ();
			Test = new Test<T> ();
			Test.Data = Data;
		}

		public bool Hello ()
		{
			Console.WriteLine (Data);
			Console.WriteLine (Test);

			SomeStruct<T> a = new SomeStruct<T> (11, Data);
			Console.WriteLine (a);
			return true;					// @MDB BREAKPOINT: foo hello
		}
	}

	class GenericTest
	{
		static void Main ()
		{
			Foo<X> x = new Foo<X> ();			// @MDB LINE: main
			Foo<Y> y = new Foo<Y> ();
			Foo<Test<int>> test = new Foo<Test<int>> ();

			x.Data.A = 5;
			y.Data.B = 9;
			test.Data.Data = 512;

			x.Hello ();
			y.Hello ();
			test.Hello ();

			Console.WriteLine (test.Data.Data);
		}
	}
}