0

I want to be able to take in a string and call GetType() and find the type. Which I do here and it works perfectly fine.

Type TypeToUse = typeof(someclass).Assembly.GetType("MyProj.Data.Stuff.MyClass");

But when I use the type I found TypeToUse to create my observable collection it says the namespace can't be found.

 ObservableCollection<TypeToUse> MyList = new ObservableCollection<TypeToUse>();

How do I fix this?

I'm actually trying to do this with a generic repository I'm assuming I have to add public virtual Type MakeGenericType(params Type[] typeArguments); to the Repository class?

Type elementType = typeof(ColorFilter).Assembly.
     GetType("Photometrics.Data.Model.Entity.PhantomModels.Chamber");
Type CoreRepoType = typeof(CoreRepository<>).Assembly.
     GetType("Photometrics.Data.Sql.Repository.CoreRepository");
Type combinedType = CoreRepoType.MakeGenericType(elementType);
Bob
  • 1,065
  • 2
  • 16
  • 36
  • The only way to do this is by using reflection. Hold on tight for a duplicate. – Jeroen Vannevel Aug 12 '14 at 16:01
  • @Future closevoters: use this one instead: http://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method – Jeroen Vannevel Aug 12 '14 at 16:02
  • Actually, creating a generic method and creating a whole generic type are not exactly the same thing. This one seems more to heart of what the OP wants: http://stackoverflow.com/questions/326285/deciding-on-type-in-the-runtime-and-applying-it-in-generic-type-how-can-i-do-t – João Mendes Aug 12 '14 at 16:04
  • @JoãoMendes: they're all the same, it's just better to close them as a duplicate of the most popular/best quality responses so the information doesn't get fragmented. – Jeroen Vannevel Aug 12 '14 at 16:05
  • I understand. I just don't think `MakeGenericType` and `MakeGenericMethod` are exactly the same. For one thing, one of them requires the use of `Activator`. – João Mendes Aug 12 '14 at 16:07

0 Answers0