Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] A question about importing object from other assemblies.

Started by nsto119 Sep 11, 2006 at 1:04 AM 3 replies 1k views
Original Post
nsto119
nsto119
Say, for example, I'm writing a class that handles user input. A bunch of the methods of that class might take a Microsoft.DirectX.DirectInput.Key enum. But, if I don't want the person using the class to have to reference and use Microsoft.DirectX.DirectInput, is there a way that I can simply import the Key enum into my own namespace so they can use it from there? As of right now, I just made my own Key enum, clicked "Go to Definition" on the DI Key enum and pasted the contents. That works, but I kind of question the legality of that.
RizMan
RizMan
As I haved had the opportunity to use it a lot yet I won't paste any code because it will certainly be wrong. But I guess what you're looking for can be found in the System.Reflection namespace. It allows to discover an Assembly at runtime.
Someone else here will certainly be able to give you details about this
conman
conman
I guess nobody cares about a copied enum...
Bob Janova
Bob Janova
If you want your code to be independent of DirectInput (which is a good idea anyway, imho), you should do basically what you have done: define your own enum and use that. Then, if you use the class with DirectInput, you should have a 'translator' to convert the DirectInput codes to your own. This is probably just a typecast in this case, but you could add translators from other input sources relatively easily.
nsto119
nsto119
Quote:
If you want your code to be independent of DirectInput (which is a good idea anyway, imho), you should do basically what you have done: define your own enum and use that. Then, if you use the class with DirectInput, you should have a 'translator' to convert the DirectInput codes to your own. This is probably just a typecast in this case, but you could add translators from other input sources relatively easily.


Yep, that's what I'll do, I guess. I've ripped the code straight from the DirectInput.Key enum and used it in my own so I can just do a straight up typecast, but I'm questioning the legality and morality of that now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.