I work in a C # web service with a common static class that accepts a type. I was wondering why this does not compile:
Type type1 = typeof(MySnazzyType); Assert.AreEqual(0, ConnectionPool_Accessor<type1>._pool.Count);
He gives this error:
Cannot find the type or namespace name 'type1' (are you missing the using directive or assembly references?)
And ReSharper, when I hang over type1 in the second line of code, says "Type or namespace name." Well, type1 is type! This is a variable of type Type ! It also does not work if I do this:
Type type1 = typeof(MySnazzyType); Assert.AreEqual(0, ConnectionPool_Accessor<typeof(type1)>._pool.Count);
I was hoping to assign my types to several Type variables and just use the ones that test different common static classes, instead of printing MySnazzyType every time. Any ideas, or I'm stuck in business:
Assert.AreEqual(0, ConnectionPool_Accessor<MySnazzyType>._pool.Count);
Edit: to clarify, MySnazzyType not a generic class and is not inherited from a generic class. The only common class is ConnectionPool_Accessor .
Thanks to Paul’s remark, “Essentially, your problem is that C # is a statically typed language”, now I know what Ruby ruined for me .;)
source share