473,396 Members | 2,129 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,396 software developers and data experts.

Initialize in and unit (cs file)

Hello,

I want to know how could i have an initialize method in a namespace.
I want to make an auto-registration component like that :

in ParentCollectionUnit

public class myParentCollection
{
public static GetInstance();
// it is a singloton parent with a addSonCollection
public addSonCollection(SonCollection NewSon);
}

in a specific SonCollection

public class SonCollection: MySpecificSon
{

}

this is the initialize process i want to make.
ParentCollectionUnit.GetInstance().addSonCollectio n(MySpecificSon);

Like that, i can have one new unit with a specific SonCollection who
are put in my project and will be automaticly refered by :
myParentCollection.

I'm used Visual Studio 2003.

Thanks for your help.

Jun 21 '06 #1
4 1596
<la**********@gmail.com> a écrit dans le message de news:
11**********************@c74g2000cwc.googlegroups. com...

| I want to know how could i have an initialize method in a namespace.
| I want to make an auto-registration component like that :

No, this is not possible in the unit alone, you are going to need a
non-instantiable class with static methods.

namespace MyCompany.MyProject
{
public class ParentCollection
{
private static SonCollection sons = new SonCollection();

private ParentCollection() { }

public static SonCollection Sons
{
get { return sons; }
}
}
}

Now you can do :

{
ParentCollection.Sons.Add(new Son());
...
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 21 '06 #2
I think it's very stange that isn't possible.
Because dotnet is compatible with COM and it is a COM method.

In VB we can create an variable with initialisation like that :
Dim myObject = myParent.mySingloton().AddSon(myLocalSon);
But in C#, all variables are on a class.

In Delphi we can use an Initialisation part for writing this code.
C++ borland used the same method.

I'm very surprise.

Joanna Carter [TeamB] wrote:
<la**********@gmail.com> a écrit dans le message de news:
11**********************@c74g2000cwc.googlegroups. com...

| I want to know how could i have an initialize method in a namespace.
| I want to make an auto-registration component like that :

No, this is not possible in the unit alone, you are going to need a
non-instantiable class with static methods.

namespace MyCompany.MyProject
{
public class ParentCollection
{
private static SonCollection sons = new SonCollection();

private ParentCollection() { }

public static SonCollection Sons
{
get { return sons; }
}
}
}

Now you can do :

{
ParentCollection.Sons.Add(new Son());
...
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


Jun 21 '06 #3
<la**********@gmail.com> a écrit dans le message de news:
11**********************@g10g2000cwb.googlegroups. com...

| I think it's very stange that isn't possible.
| Because dotnet is compatible with COM and it is a COM method.

Not necessarily; there is nothing that says that all units contain COM
methods, therefore why would you expect all languages to support procedures
in the unit ?

| In VB we can create an variable with initialisation like that :
| Dim myObject = myParent.mySingloton().AddSon(myLocalSon);
| But in C#, all variables are on a class.

| In Delphi we can use an Initialisation part for writing this code.
| C++ borland used the same method.

Both VB for .NET and Delphi for .NET create a wrapper class for the code
unit; just because you don't see it in the code, doesn't mean the compiler
doesn't make such a class. And that class contains static methods that are
constructed out of your unit procedures.

Welcome to the world of "real" OO programming :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 21 '06 #4
Thanks for your help Joanna.
Joanna Carter [TeamB] wrote:
<la**********@gmail.com> a écrit dans le message de news:
11**********************@g10g2000cwb.googlegroups. com...

| I think it's very stange that isn't possible.
| Because dotnet is compatible with COM and it is a COM method.

Not necessarily; there is nothing that says that all units contain COM
methods, therefore why would you expect all languages to support procedures
in the unit ?

| In VB we can create an variable with initialisation like that :
| Dim myObject = myParent.mySingloton().AddSon(myLocalSon);
| But in C#, all variables are on a class.

| In Delphi we can use an Initialisation part for writing this code.
| C++ borland used the same method.

Both VB for .NET and Delphi for .NET create a wrapper class for the code
unit; just because you don't see it in the code, doesn't mean the compiler
doesn't make such a class. And that class contains static methods that are
constructed out of your unit procedures.

Welcome to the world of "real" OO programming :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


Jun 22 '06 #5

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

Similar topics

2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
9
by: Vipul Jain | last post by:
Can any one please tell me what is the difference between global scope of an variable and file scope of an variable. Vipul
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
3
by: Amy L. | last post by:
Is there a Buffer size that is optimial based on the framework or OS that is optimal when working with chunks of data? Also, is there a point where the buffer size might not be optimal (too...
0
by: Mark | last post by:
Hello Please forgive me if this has come through twice, I don't see the original post anywhere.. I have one Windows 98 system that started producing the following error, while other Windows 98...
4
by: bob | last post by:
Why doesn't c++ let me initialize static members like this: class MySound { static CSoundManager* g_pSoundManager = NULL; };
1
by: =?Utf-8?B?SmFzb24=?= | last post by:
Hi all, I have set up ODBC connection through data source configuration wizard and I can run my application normally. But without any changes of my application & ODBC connection, the error is...
9
by: sidhx | last post by:
hi I wanted to develop php unit file testing. Like showing each php file with "test" link (or button).When we click the "test" associated to that file it dispay the output. plz help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
tracyyun
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 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.