Friday, February 6, 2009

Edge Cases

It's nice to pretend edge cases don't exist or aren't important, but they do and they are...  Try as you might, someone will stumble upon it and the world will collapse under the weight of invalidated assumptions.


Here is one that I've been dealing with lately:

public class Container<T>
    public class Outer
        public class Inner : Outer


1. What does typeof(Inner).GetGenericArguments().Length return?

2a. What does typeof(Inner).GetGenericArguments()[0].ToString() return?

2b. How about typeof(Inner).GetGenericArguments()[0].FullName?

3. What does typeof(Inner).GetGenericArguments()[0].DeclaringType.ToString() return?

3b. How about typeof(Inner).GetGenericArguments()[0].DeclaringType.FullName?

4a. What does typeof(Inner).BaseType.GetGenericArguments()[0].DeclaringType.ToString() return?

4b. How about typeof(Inner).BaseType.GetGenericArguments()[0].DeclaringType.FullName?

5a. What does typeof(Inner).BaseType.ToString() return?

5b. How about typeof(Inner).BaseType.FullName?


(Select text to reveal.)

1. 1

2a. "T"

2b. null

3a. "Container`1+Outer+Inner[T]"

3b. "Container`1+Outer+Inner"

4a. "Container`1+Outer+Inner[T]"

4b. "Container`1+Outer+Inner"

5a. "Container`1+Outer[T]"

5b. null


No comments: