473,387 Members | 1,520 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,387 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 1004
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
jinu1996
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 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.