|
Hi Amit,
just clear the text property of the form and change the FormBorderStyle to Single/Resizable..
Regards,
Pramod
|
|
|
|
|
Hi everybody,
I am developing a library for my company and encounter a problem. In my code, I need to know and enumerate through all the derived classes of a base class. Are there any way to get the derived classes of a base class by using reflection in C#?
Hope your replies, thanks.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
You can iterate over every type in an assembly and check IsAssignableFrom(yourBaseType)
|
|
|
|
|
I got it! Thank you for you helping!
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
Can we know why you do this? It's usually a bad idea for code to know derived classes from base classes.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
Here is the context that I use reflection:
- The library has a base class, e.g AbstractAlgorithm, and some derived classes, e.g ConcreteAlgorithm1, ConcreteAlgorithm2, ... We can get an algorithm instance like this: AbstractAlgorithm algo = new ConcreateAlgorithm1();
- I want to provide another way for client to get an algorithm instance by its name like this: AbstractAlgorithm algo = AlgorithmFactory.createInstance("XYZ algorithm");
So I add an abstract method "getName()" to AbstractAlgorithm base class and each concreate algorithm class implements this method to return its name. The "createInstance(string)" method of AlgorithmFactory will use reflection to enumerate through the derived classes of AbstractAlgorithm, call their "getName()" methods to select the right algorithm class. After that, I use .NET class Activator to create an algorithm instance of the selected class. By doing this (instead of using "switch case" statement), the "createInstance(string)" method is unchanged when new concrete algorithm classes are added to the library.
Is it a right design?
Hope to see your opinion.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
How about simply passing the type of the derived class, instead of a string representing the type? Something like
AlgorithmFactory.CreateInstance(typeof(ConcreteAlgorithm1));
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I think client will prefer short and friendly name to long and hard to remember class name. I just study it from the Java Cryptography Framework. We can get an MD5 hash algorithm like this: MessageDigest md = MessageDigest.getInstance("MD5"); We do not need to know the name of the class that implements the MD5 hash algorithm.
Hope to see your opinion.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
Yeah, it's a tradeoff :- with type names, you get compile time errors if the user passes an invalid type, with strings, you don't. OTOH, like you said, it's more convenient for the users..
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yes, it's a trade-off.
Thanks for sharing your opinion.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
hi guys.... juz wanna ask a favor. can you give me some sample codes of C#. i rili think that inventory sample codes will help me... thanks again....
|
|
|
|
|
Have you searched MSDN? There is lots of sample code that is well expained with good annotation. Have you searched other resources? If you have written some code that isn't working and you don't understand why then we can help. If you need a pointer to a particular coding technique we can point you in the right direction. Your request is too vague. If you are desperate for a whole inventory system in C# why not search through some open source repositories.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
knight_sky wrote: can you give me some sample codes of C#.
What color? Size? Flavor? Please be specific. There's a lot of C# code to choose from.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
go CHEAT somewhere else...
get some books
do a google search
|
|
|
|
|
You're comment of cheating makes no sense what so ever.
I agree with the google search and books are but that is not really a good idea unless you know what you are looking for.
not all books related to programming are idea. Most Theory are questionable.
|
|
|
|
|
aerosmith2k1 wrote: cheating makes no sense what so ever
he's asking for complete source to an inventory control program. if not in this post, in another post he made. yeah i call that cheating.
|
|
|
|
|
hi guys! i'm an information technology student. i just want to seek help regarding my thesis. its about sales inventory system and book directory system of a bookstore. our prof want us to use C#. well it is very new to all of us, so i rili nid ur help. thanks... i'll wait for u'r reply. i'm rili desperate.
pls and thank you!
|
|
|
|
|
|
Be specific - what exactly do you need help with. You just made a series of vague comments that no one can really use to help you.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Dude. Read some books. Think. Learn. There are no shortcuts.
|
|
|
|
|
G'day folks,
I just implemented a winform containing a listview. The listview simply lists all the files present in a directory with the name and its respective icon in one column. As I was trying to get an understanding on how Win32.SHGetFileInfo works.
The process of actually adding the information was done via a separate thread. What I had discovered that if one of my files contained an outlook message file, it will not display the icon for outlook instead it displays the generic windows icon. The generic windows icon is the same as when windows os cannot seem to associate an application with a file.
Now if I were to display the files and its respective icon in the listview without the assistance of a thread, the outlook icon appears in the listview. So far it works fine with any other file ie. txt, word, excel etc. The samething happens with .net 1.1 and 2.0
Anyone got any ideas as to why this would be happening ?
thanks
|
|
|
|
|
|
thanks for the reference. I always saw BeginInvoke but didnt realise what it did till now.
|
|
|
|
|
I have an interesting problem that I am looking for some advice on. Basically I have a protocol library, where each PDU is a class. Thus the library is a collection of individual classes that are stateless.
Meanwhile, I have a need to aquire some housekeeping info via a one time register function. I'd like for this function to make the housekeeping info persistent or semi-persistent so that thet data would be available to the other classes as they are instantiated.
Now, I could use XML to write out persistant data but the overhead in file I/O seems quite underdesirable in a near real time application. I could write a value to the Registry, but again there is a performance hit. Finally I have considered kicking off a thread which the instantiated classes could interrogate but that feels over the top.
If only you could create a Shared Memory Region like the good ol' days (just kidding). But if you have tackled a similar problem, or know of an elegant approach please let me know. Thanks in advance!
Mike
|
|
|
|
|
mcljava wrote: PDU
What's a PDU?
If all this is happening in one application then reading an XML file at start up then holding the data internally isn't too bad. The other classes could then query the central housekeeping class. If it needs to write stuff out to persist it then it could do so when the application is shut down or at regular intervals so it doesn't disrupt the flow of the rest of the application.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|