Is there a way to programmatically get a list of classes that are contained
in a namespace? I have a namespace that holds a bunch of different data
classes, all derived from the same base class, that the user will choose
from. Rather than manually creating one of each type and putting it in a
list I was wondering if there was a way to programmatically query a
namespace for a list of types.
Thanks,
jim 6 1087
Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no
physical boundaries. You can have classes in different namespaces in
different assemblies.
What you can do, however, is get a list of types from each assembly that
is loaded, and then query the namespace from the type, and then group them
appropriately.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl... Is there a way to programmatically get a list of classes that are contained in a namespace? I have a namespace that holds a bunch of different data classes, all derived from the same base class, that the user will choose from. Rather than manually creating one of each type and putting it in a list I was wondering if there was a way to programmatically query a namespace for a list of types.
Thanks, jim
That will work. All of these classes are in their own assembly. How would
I do that? Can you point me in the right direction?
Thanks,
Jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e5**************@TK2MSFTNGP10.phx.gbl... Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no physical boundaries. You can have classes in different namespaces in different assemblies.
What you can do, however, is get a list of types from each assembly that is loaded, and then query the namespace from the type, and then group them appropriately.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:%2***************@TK2MSFTNGP14.phx.gbl... Is there a way to programmatically get a list of classes that are contained in a namespace? I have a namespace that holds a bunch of different data classes, all derived from the same base class, that the user will choose from. Rather than manually creating one of each type and putting it in a list I was wondering if there was a way to programmatically query a namespace for a list of types.
Thanks, jim
Jim,
If you get the programattic representation of the assembly they are in
(the Assembly instance), then you can call GetTypes. This will return an
array of Type instances which represent the types in the array.
Once you have that, you can cycle through the array, and check the
Namespace property of each type. If it matches the one you are looking for,
then store the instance (in an ArrayList, perhaps), and then process the
list left over when you are done.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl... That will work. All of these classes are in their own assembly. How would I do that? Can you point me in the right direction?
Thanks, Jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:e5**************@TK2MSFTNGP10.phx.gbl... Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no physical boundaries. You can have classes in different namespaces in different assemblies.
What you can do, however, is get a list of types from each assembly that is loaded, and then query the namespace from the type, and then group them appropriately.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:%2***************@TK2MSFTNGP14.phx.gbl... Is there a way to programmatically get a list of classes that are contained in a namespace? I have a namespace that holds a bunch of different data classes, all derived from the same base class, that the user will choose from. Rather than manually creating one of each type and putting it in a list I was wondering if there was a way to programmatically query a namespace for a list of types.
Thanks, jim
Jim,
Take a look at System.Reflection.Assembly - this has the GetTypes() method,
which gives you a list of types that you can drill down into. You can get the
currently running assembly using the static method
System.Reflection.Assembly.GetCallingAssembly()
Hope this helps,
Chris.
"Jim H" wrote: That will work. All of these classes are in their own assembly. How would I do that? Can you point me in the right direction?
Thanks, Jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:e5**************@TK2MSFTNGP10.phx.gbl... Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no physical boundaries. You can have classes in different namespaces in different assemblies.
What you can do, however, is get a list of types from each assembly that is loaded, and then query the namespace from the type, and then group them appropriately.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:%2***************@TK2MSFTNGP14.phx.gbl... Is there a way to programmatically get a list of classes that are contained in a namespace? I have a namespace that holds a bunch of different data classes, all derived from the same base class, that the user will choose from. Rather than manually creating one of each type and putting it in a list I was wondering if there was a way to programmatically query a namespace for a list of types.
Thanks, jim
Thanks, that helps a lot. How can I create and instance of a Type I find?
Type T = MyAssembly.GetTypes[0];
//I know this does not work but this is what I want to do.
//BaseClass is the base class that T was derived from.
BaseClass lTemp = new T;
Thanks again,
jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eQ**************@TK2MSFTNGP10.phx.gbl... Jim,
If you get the programattic representation of the assembly they are in (the Assembly instance), then you can call GetTypes. This will return an array of Type instances which represent the types in the array.
Once you have that, you can cycle through the array, and check the Namespace property of each type. If it matches the one you are looking for, then store the instance (in an ArrayList, perhaps), and then process the list left over when you are done.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:Oj**************@TK2MSFTNGP12.phx.gbl... That will work. All of these classes are in their own assembly. How would I do that? Can you point me in the right direction?
Thanks, Jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:e5**************@TK2MSFTNGP10.phx.gbl... Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no physical boundaries. You can have classes in different namespaces in different assemblies.
What you can do, however, is get a list of types from each assembly that is loaded, and then query the namespace from the type, and then group them appropriately.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:%2***************@TK2MSFTNGP14.phx.gbl... Is there a way to programmatically get a list of classes that are contained in a namespace? I have a namespace that holds a bunch of different data classes, all derived from the same base class, that the user will choose from. Rather than manually creating one of each type and putting it in a list I was wondering if there was a way to programmatically query a namespace for a list of types.
Thanks, jim
Found it.
Assembly.CreateInstance()
Thanks for your help.
jim
"Jim H" <no****@jimsaccount.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl... Thanks, that helps a lot. How can I create and instance of a Type I find?
Type T = MyAssembly.GetTypes[0];
//I know this does not work but this is what I want to do. //BaseClass is the base class that T was derived from. BaseClass lTemp = new T;
Thanks again, jim "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eQ**************@TK2MSFTNGP10.phx.gbl... Jim,
If you get the programattic representation of the assembly they are in (the Assembly instance), then you can call GetTypes. This will return an array of Type instances which represent the types in the array.
Once you have that, you can cycle through the array, and check the Namespace property of each type. If it matches the one you are looking for, then store the instance (in an ArrayList, perhaps), and then process the list left over when you are done.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:Oj**************@TK2MSFTNGP12.phx.gbl... That will work. All of these classes are in their own assembly. How would I do that? Can you point me in the right direction?
Thanks, Jim
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:e5**************@TK2MSFTNGP10.phx.gbl... Jim,
Unfortunately, there is not. A namespace is a logical grouping, with no physical boundaries. You can have classes in different namespaces in different assemblies.
What you can do, however, is get a list of types from each assembly that is loaded, and then query the namespace from the type, and then group them appropriately.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jim H" <no****@jimsaccount.com> wrote in message news:%2***************@TK2MSFTNGP14.phx.gbl... > Is there a way to programmatically get a list of classes that are > contained in a namespace? I have a namespace that holds a bunch of > different data classes, all derived from the same base class, that the > user will choose from. Rather than manually creating one of each type > and putting it in a list I was wondering if there was a way to > programmatically query a namespace for a list of types. > > Thanks, > jim >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David |
last post by:
hello.
when doing the simple following computation, the value put into the variable
numMinusOne is NOT the same as what the computation is showed to be in the
Watch window!!
here is the code:...
|
by: Rob Ristroph |
last post by:
Hi,
It's pretty unhelpful to post "I have a huge piece of code that
crashes in strange places, what's the problem?" but that's basically
my problem and I really am at my wit's end.
The piece...
|
by: FrankEsser |
last post by:
Hello!
I am not an expert on C++ programming and therefor I have a question:
We use a kind of communication server that was written in C++
especially for our company. It just takes incoming...
|
by: Werner Partner |
last post by:
I use a page created by php.
It should show two pictures of a person an a short text.
If there are no picture, nothing is shown, if there is no text, nothing
is shown.
There a about 20...
|
by: Richard Hollenbeck |
last post by:
I've asked this question before but over a month later I still don't have an
answer. A few people did try to help and I am thankful, but I really didn't
get the problem solved. I'll try to ask...
|
by: unknown |
last post by:
Hi,
I am developing an online book store with shopping cart.
My shopping cart is represented as a Xml server control
and I am using an XSLT to render it at the client side.
I am using an...
|
by: Mike C# |
last post by:
Hi all,
I keep getting a strange error and can't pin it down. The message is:
This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's...
|
by: zacks |
last post by:
I am developing an app in VS2005 (actually in VB.NET but this
question, I believe, would apply to any .NET language) that is used to
design the contents of an XML file. One of potential items that...
|
by: |
last post by:
I have signed up to a dotnet hosting account and I have a dotnet app
called CommunityServer, which allows me to setup my own news
forums. The path of one of my forums (the third one) is
...
|
by: Heinrich Pumpernickel |
last post by:
i got the following strange extra question in a written test
today . since the test was abt c/c++ i guess this is on topic here
--8<--
22) Consider the following quote:
"If Mickey's a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |