0

My Code is like
Assembly assemblyX = Assembly.Load("xyz.abc.DataObjects"); Type t = assemblyX.GetType("xyz.abc.DataObjects." + ValueStr); Everything is good till this point. Now i want to implement interface on 't' which is 'xDataObject' and require a generic i.e "CurrentDataObject" in < > operators like xDataObject<CurrentDataObject>. This interface consists many member functions, which I want to use in reflection. According to my research on it, the problem is in this next line, which works fine until we don't need interface i.e
Object objClass = (Object)Activator.CreateInstance(t);
Help me. I'm new to Generics. Thank you.

emles
  • 35
  • 10

2 Answers2

0

You can take a look at Castle DynamicProxy. It lets you create proxies of your types on run-time which implement interfaces, base classes and many other things.

Check its documentation here.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
  • i don't wanna do this on runtime bro. i wanna access all member functions on that instance, i mean, it will probably showing all member functions through intellisense after implementing Interface on it (Instance). – emles Jan 28 '16 at 09:01
  • Reflection means runtime, seems you need to explain better what you want to do and when. – Lasse V. Karlsen Jan 28 '16 at 09:11
  • @emles I would avoid the "bro" thing. While it's during run-time, you're creating new types as if they would be created during compile-time using Reflection Emit under the hoods. See for example this other Q&A: http://stackoverflow.com/questions/1651455/using-reflection-emit-to-create-a-class-implementing-an-interface. Instead of using this lower-level API, Castle DynamicProxy makes it easier. – Matías Fidemraizer Jan 28 '16 at 09:15
  • @emles Recently I used DynamicProxy to implement this project from the scratch: http://matiasfidemraizer.com/trackerdog Maybe you can take a look at my code to get ideas.. – Matías Fidemraizer Jan 28 '16 at 09:16
  • yeah, i know anyways, the only problem is that generic between angle brackets in interface. – emles Jan 28 '16 at 09:43
0

There is no native solution for what you want as generic checking is made at compile time. At runtime you must use dynamic in your code or the previously recommended dll.

Peter Krassoi
  • 571
  • 3
  • 11