473,231 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Classes constructor

Hello guys!
I've a strange situation..
I have to fill a list with all classes defined in a particular
namespace..
I have to add all class defined in that namespace (there are many
classes..)
So instead to make
list.Add(new class1());
list.Add(new class2());
....
Is it possible to write
foreach (class in "MyProject.ClassesToAdd")
list.Add(classCostructor(class));
where "MyProject.ClassesToAdd" is a namespace?

thank you very much!
Giojo

Dec 5 '05 #1
1 1003
Giojo wrote:
I've a strange situation..
I have to fill a list with all classes defined in a particular
namespace..
I have to add all class defined in that namespace (there are many
classes..)
So instead to make
list.Add(new class1());
list.Add(new class2());
...
Is it possible to write
foreach (class in "MyProject.ClassesToAdd")
list.Add(classCostructor(class));
where "MyProject.ClassesToAdd" is a namespace?


You can't do it quite like that. For any one assembly, you can list the
types in the assembly (Assembly.GetTypes()), and pick out each one in
the right namespace (Type.Namespace). Also, for any type, you can call
a constructor reflectively, eg using Activator.CreateInstance. Between
the two of those, I think you can do what you want. If you have any
problems with either of the steps, give details (and how far you've
got) and we should be able to put you back on the right track.

Jon

Dec 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Randy | last post by:
Problem reduced to simplist form: abstract class myBase { myBase(int x) { Console.Writeline("x = {0}", x); } } class mySubClass : myBase
7
by: sureshsundar007 | last post by:
Hi all, I'm trying to inherit the SimpleWorkerRequest class. my code is like this.. public class Request : SimpleWorkerRequest { public Request(): base(String.Empty,String.Empty,null) { }
9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.