Re: Reflection and arrays
Make the definition of A public in 3rd party dll.
Re: Reflection and arrays
maybe something like this...
Code:
A[] 3rdPartyArray = new A[];
SomeFunction(ref 3rdPartyArray);
Re: Reflection and arrays
Thanks for your answers but its not that simple.
The class is public and declaring
A[] 3rdPartyArray = new A[];
would work fine if I didnt need to use reflection.
Unfortunately, I have to use reflection and therefore need to do something like this:
List<A> myList = new List<A>();
But I have to retrieve A via reflection...because I dont want to reference the assembly in my project file.
Re: Reflection and arrays
Quote:
Originally Posted by SSix2
Thanks for your answers but its not that simple.
The class is public and declaring
A[] 3rdPartyArray = new A[];
would work fine if I didnt need to use reflection.
Unfortunately, I have to use reflection and therefore need to do something like this:
List<A> myList = new List<A>();
But I have to retrieve A via reflection...because I dont want to reference the assembly in my project file.
You can not mix "have to" (absolute requirement/no other options) and "want to" (a desire) ....WHICH is it????
Re: Reflection and arrays
You should use object[] or ArrayList (the .NET 1.1 version of List which works on System.Object).
If you have no reference to type A that's all you can do.
You can then invoke methods on the instances of the object (items in the array) using reflection.
Darwen.
Re: Reflection and arrays
Quote:
Originally Posted by SSix2
But I have to retrieve A via reflection...because I dont want to reference the assembly in my project file.
This seems me to be a bit strange.
If you have the rights to use the 3rd party dll why then not simple reference to it. if you want to use it, you will have to reference to it.
There is a tool in the web names something like LutzRoedersReflector which can be used to analyse dlls. So even if I cannot get your intentions background this will maybe answer your question.
Re: Reflection and arrays
Quote:
Originally Posted by JonnyPoet
Lutz Roeder's Reflector.
Actually Lutz has turned that project over to RedGate and moved on to "bigger and better" things....(This tool should be part of EVERY .Nertdevelopers environment).
Re: Reflection and arrays
TheCPUWizard: I need to not reference the assembly in the project. Therefore, I need to use reflection inorder to obtain A's type and create a array. Maybe not but I assumed reflection would be the best mechanism to help in the matter.
darwen: I was hoping these werent the only options. Nutz...
JonnyPoet: Certain enviroments that I work in require somethings not be distributed. Currently I am doing the obvious (just referencing the assembly in the project) and everything works fine but it causes some merging and maintenance issues later in the process.
eh. I thought I would just ask to see if someone had a neat idea.
Re: Reflection and arrays
To utilize the class, you have to load it. Period.
This is independant of referencing it at the project level (giving you compile time access) or of dynamically loading it.
So since your code will need access to the DLL at runtime, I fail to seew why you can not reference it as part of the project.
This has NOTHING to do with distributing the DLL.....
Re: Reflection and arrays
I thought he might be writing some form of plug-in system.
But in a plug-in system you usually have interfaces which are in a referenced assembly and included in the project. These are then implemented by the objects in the dynamically loaded assembly to avoid calling the objects in question by reflection.
Darwen.
Re: Reflection and arrays
Quote:
Originally Posted by darwen
I thought he might be writing some form of plug-in system.
But in a plug-in system you usually have interfaces which are in a referenced assembly and included in the project. These are then implemented by the objects in the dynamically loaded assembly to avoid calling the objects in question by reflection.
Darwen.
Exactly...in which case all programmatic interaction would be with members of the interface. So you might have a List<Interface> but you would not have a List<Class>...
Re: Reflection and arrays
Quote:
Originally Posted by TheCPUWizard
To utilize the class, you have to load it. Period.
This is independant of referencing it at the project level (giving you compile time access) or of dynamically loading it.
So since your code will need access to the DLL at runtime, I fail to seew why you can not reference it as part of the project.
The DLL (actually DLLs) can not be used in all environments that I work in. The project file must be updated in other departments and causes time/effort.
Quote:
Originally Posted by TheCPUWizard
This has NOTHING to do with distributing the DLL.....
I was not referring to distribution to the customer.
I was asking a question concerning arrays and reflection. I guess it cant be done.