open-generics

AutoFixture: Configuring an Open Generics Specimen Builder

非 Y 不嫁゛ 提交于 2019-11-30 19:47:12
I have an object model that uses Open Generics (Yes, yes, now I have two problems; that's why I'm here :) :- public interface IOGF<T> { } class C { } class D { readonly IOGF<C> _ogf; public D( IOGF<C> ogf ) { _ogf = ogf; } } I'm trying to get AutoFixture to generate Anonymous instances of D above. However, on its own, AutoFixture doesn't have a built in strategy for building an IOGF<> and hence we observe: public class OpenGenericsBinderDemo { [Fact] public void X() { var fixture = new Fixture(); Assert.Throws<Ploeh.AutoFixture.ObjectCreationException>( () => fixture.CreateAnonymous<D>() ); }

AutoFixture: Configuring an Open Generics Specimen Builder

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 03:58:19
问题 I have an object model that uses Open Generics (Yes, yes, now I have two problems; that's why I'm here :) :- public interface IOGF<T> { } class C { } class D { readonly IOGF<C> _ogf; public D( IOGF<C> ogf ) { _ogf = ogf; } } I'm trying to get AutoFixture to generate Anonymous instances of D above. However, on its own, AutoFixture doesn't have a built in strategy for building an IOGF<> and hence we observe: public class OpenGenericsBinderDemo { [Fact] public void X() { var fixture = new

Get all types implementing specific open generic type

这一生的挚爱 提交于 2019-11-28 21:03:05
How do I get all types that implementing a specific open generic type? For instance: public interface IUserRepository : IRepository<User> Find all types that implement IRepository<> . public static IEnumerable<Type> GetAllTypesImplementingOpenGenericType(Type openGenericType, Assembly assembly) { ... } Nick VanderPyle This will return all types that inherit a generic base class. Not all types that inherit a generic interface. var AllTypesOfIRepository = from x in Assembly.GetAssembly(typeof(AnyTypeInTargetAssembly)).GetTypes() let y = x.BaseType where !x.IsAbstract && !x.IsInterface && y !=

Get all types implementing specific open generic type

有些话、适合烂在心里 提交于 2019-11-27 01:27:16
问题 How do I get all types that implementing a specific open generic type? For instance: public interface IUserRepository : IRepository<User> Find all types that implement IRepository<> . public static IEnumerable<Type> GetAllTypesImplementingOpenGenericType(Type openGenericType, Assembly assembly) { ... } 回答1: This will return all types that inherit a generic base class. Not all types that inherit a generic interface. var AllTypesOfIRepository = from x in Assembly.GetAssembly(typeof

What exactly is an “open generic type” in .NET? [duplicate]

假装没事ソ 提交于 2019-11-26 03:17:26
问题 This question already has answers here : Generics -Open and closed constructed Types (3 answers) Closed 6 years ago . I was going through Asp.Net MVC lesson and learned that, for a method to qualify as an action for a controller, It must not have an \"open generic type\" I understand generics somewhat and use them to some extent, but: What is an open generic type in .Net. Is there such a thing as a closed generic type ? Open generic type is a term not used very often. What is used / confused