Jump to content
  • Advertisement
Sign in to follow this  
fanaticlatic

[.net] Retrieving Type objects

This topic is 3970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to create a delegate using delegate.CreateDelegate(typeof(delegateObj), (Type)scriptType, (string)methodname) where scriptType is built using scriptType = Type.GetType(asmQualifiedName,true,true); this way of delegate creation currently forces me to store the whole assembly qualified name in my script file for the class that holds the method 'methodname' which as you probably know is quite a hefty string: "someProject.SomeObjType, someProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" ideally i would just like to store the strings "someProject.SomeObjType" or even better "SomeObjType" then build the Type object 'scriptType' from that. If anyone knows a method that will take a fullname or name of a class rather than the assembley qualified name i would be interested to know. i should point out that i thought about creating a constant string with the back end of that assembley name but that would restrict which classes delegates could be created from. thanks in advance, mark.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure I totally understand your question. But if you want a more flexible type locating system, you can write one yourself easily. Look at the Assembly class. You can do

Assembly a = Assembly.GetExecutingAssembly();

Type[] types = a.GetTypes();


to get a list of all types in the assembly which contains the code that's currently executing. Then you can iterate through each type and compare it to your strings. You can also take an assembly and search through all its referenced assemblies using a.GetReferencedAssemblies() to get an array of assemblies that are referenced, and you can search through each of the types in those assemblies.

You can go further than that, and do AppDomain.GetAssemblies() which returns all loaded assemblies, including any assemblies that you have loaded through reflection at runtime.

Share this post


Link to post
Share on other sites
Well considering you didn't fully understand my question thats a damn good answer, i'll have a play with it but i think you hit the nail on the head cheers mate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!