OpenGenericWithOpenService : IGenericService {} Now it's important that when you ask that for the interfaces it implements, you know that you can convert to IGenericService). GetGenericArguments(); Type constructed = typeof(IGenericService). MakeGenericType(typeParams); typeof(OpenGenericWithOpenService).GetInterfaces().First() .
ShouldEqual(constructed); } If you change the class to implement (say) IGenericService.
OpenGenericWithOpenService doesn't implement just an arbitrary IGenericService - it implements IGenericService for the same T as the class. The best way to show this is to change the class slightly: public class OpenGenericWithOpenService : IGenericService {} Now it's important that when you ask that for the interfaces it implements, you know that you can convert to IGenericService but (coincidences aside) not IGenericService or any other implementation. In other words, it's not entirely open - it's pinned down to the same type argument that the class has.
I've never been very good with the generics terminology, but I hope you see what I mean. IGenericService is a type waiting to be given a type argument; in this case you've got the type argument - it just happens to be another type parameter! Here's a test which will pass: TestMethod public void can_get_open_generic_interface_off_of_implementor() { Type typeParams = typeof(OpenGenericWithOpenService).
GetGenericArguments(); Type constructed = typeof(IGenericService). MakeGenericType(typeParams); typeof(OpenGenericWithOpenService).GetInterfaces().First() . ShouldEqual(constructed); } If you change the class to implement (say) IGenericService instead, it will fail.
Yeah. Just found more on this here: stackoverflow. Com/questions/511620/generic-types-not-equal The test passes if I use typeof(OpenGenericWithOpenService).GetInterfaces().First().
GetGenericTypeDefinition() – George Mauer Apr 20 '10 at 20:35 Still don't quite get why OpenGenericWithOpenService doesn't implement IGenericService...? – thecoop Apr 20 '10 at 20:35 Brilliant! I've found that reasoning about the reflection semantics of generics (open or otherwise) is complicated. I think the subject deserves treatment in a book.
Hmmm, who do we know that could do that... :) – LBushkin Apr 20 '10 at 20:37 @thecoop: Suppose we had class OpenGenericWithOpenService : IGenericService, IGenericService, IGenericService (with an interface where that was possible). Wouldn't you want to be able to distinguish between the three interfaces it's implementing? – Jon Skeet Apr 20 '10 at 20:43 1 Similar gotcha in this blog post: blogs.msdn.Com/weitao/archive/2008/03/19/… – Hans Passant Apr 20 '10 at 20:50.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.