Skip to content

Instantly share code, notes, and snippets.

@default-kramer
Created October 30, 2013 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save default-kramer/7239781 to your computer and use it in GitHub Desktop.
Save default-kramer/7239781 to your computer and use it in GitHub Desktop.
class A<T>
{
public string Foo { get { return "hello"; } }
}
class B<T> : A<T> { }
// this is OK (because A's generic parameter doesn't go to its base class?)
class Ok<T> : A<Ok<T>> { }
// this is broken (because B's generic parameter tries to go to a base class?)
class Broken<T> : B<Broken<T>> { }
[TestMethod]
public void MyTestMethod()
{
dynamic d = new Ok<string>();
var value = d.Foo;
Assert.AreEqual("hello", value);
d = new Broken<string>();
value = d.Foo; // StackOverflowException
Assert.AreEqual("hello", value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment