C# code

  • Thread starter Thread starter Pohihihi
  • Start date Start date
P

Pohihihi

I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
Got no time for a complete example, but look into "public partial class"
declaration syntax...
 
The best way to do this in 2003 would be by creating "abstract" classes. You cant name the class the same as the derived class but I think this would give you the functionality you want.

You can create folders in your 2003 projects and still access those classes. Classes created in these subfolders take on the namesspace of the subfolder appended to the project namespace.

Example:

MyProject
ClassGroup1
MyClass.cs

In that structure the namespace of "MyClass" would be by default "MyProject.ClassGroup1"

Eric Renken

I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
I do have classes abstract but I wanted to organize and make big files small to make it more managable. Folder thing will be help in that case. Thanks.

The best way to do this in 2003 would be by creating "abstract" classes. You cant name the class the same as the derived class but I think this would give you the functionality you want.

You can create folders in your 2003 projects and still access those classes. Classes created in these subfolders take on the namesspace of the subfolder appended to the project namespace.

Example:

MyProject
ClassGroup1
MyClass.cs

In that structure the namespace of "MyClass" would be by default "MyProject.ClassGroup1"

Eric Renken

I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
As a matter of style, instead of splitting one class into multiple
source files, it is generally better to split it into multiple classes
first, then split out the helper classes into separate source files.
Inside every large class is a number of smaller classes screaming to be
let out.
 
I can see the frustration ahead. Walking into company abc and finding a crap ton of classes each spread across many files. I bet someone even comes up with some nifty naming convention for said files to easily (lol) keep track of what method is where (just say no). Not even solid gold meatballs could save that spaghetti. Please excuse me I just think this is a bad idea.

--

Derek Davis
(e-mail address removed)
I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
Surely the scenario you give does make it soung a bad idea. I am not looking for a big mess later. It is just a way to organize GUI forms. Bracking class might not be a good idea (but still it is supported in full swing in vs2005) but organizing similer controls or GUIs is. It is happening for many years now, it is just that I am trying to find if it is possible in vs IDE. As one of the replies on this thread suggested how folders will work and I guess that solves my problem.

Thanks.
"carion1" <ddavis76 _at_ gmail _dot_ com> wrote in message I can see the frustration ahead. Walking into company abc and finding a crap ton of classes each spread across many files. I bet someone even comes up with some nifty naming convention for said files to easily (lol) keep track of what method is where (just say no). Not even solid gold meatballs could save that spaghetti. Please excuse me I just think this is a bad idea.

--

Derek Davis
(e-mail address removed)
I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
Whenever a tool (especially a modern tool such as C# .NET) does not easily
lend itself to a certain way of doing things then:

maybe not ask: "How can I do it this way?"

but rather ask: "Maybe this is not the best way to do it?"

The purpose of classes is for logical object organization. If you have a
reason why you want other class elements in another file then maybe:

a.) you need another class.

or b.) use #region to separate/hide the various logical groups of items
within the class.
 
Greg said:
Whenever a tool (especially a modern tool such as C# .NET) does not easily
lend itself to a certain way of doing things then:

maybe not ask: "How can I do it this way?"

but rather ask: "Maybe this is not the best way to do it?"

That's an excellent, excellent point. It's one which is particularly
worth bearing in mind when transitioning from one language or platform
to another - not just when porting code, but when approaching a problem
which you might have tackled in one way in another language, but which
seems a pain in the new one.

Hear hear, basically :)
 
Well said.

--

Derek Davis
(e-mail address removed)

Greg said:
Whenever a tool (especially a modern tool such as C# .NET) does not easily
lend itself to a certain way of doing things then:

maybe not ask: "How can I do it this way?"

but rather ask: "Maybe this is not the best way to do it?"

The purpose of classes is for logical object organization. If you have a
reason why you want other class elements in another file then maybe:

a.) you need another class.

or b.) use #region to separate/hide the various logical groups of items
within the class.
 
If you really think about it, proper class design will render exactly what you want in a slightly different fashion. In terms of organization you might think about an N-Tier design even if all the pieces will reside on the client machine.

--

Derek Davis
(e-mail address removed)
Surely the scenario you give does make it soung a bad idea. I am not looking for a big mess later. It is just a way to organize GUI forms. Bracking class might not be a good idea (but still it is supported in full swing in vs2005) but organizing similer controls or GUIs is. It is happening for many years now, it is just that I am trying to find if it is possible in vs IDE. As one of the replies on this thread suggested how folders will work and I guess that solves my problem.

Thanks.
"carion1" <ddavis76 _at_ gmail _dot_ com> wrote in message I can see the frustration ahead. Walking into company abc and finding a crap ton of classes each spread across many files. I bet someone even comes up with some nifty naming convention for said files to easily (lol) keep track of what method is where (just say no). Not even solid gold meatballs could save that spaghetti. Please excuse me I just think this is a bad idea.

--

Derek Davis
(e-mail address removed)
I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
When I said N-Tier design I should have been a little more clear. I mean break things up into diff projects (business layer, data layer).

--

Derek Davis
(e-mail address removed)
"carion1" <ddavis76 _at_ gmail _dot_ com> wrote in message If you really think about it, proper class design will render exactly what you want in a slightly different fashion. In terms of organization you might think about an N-Tier design even if all the pieces will reside on the client machine.

--

Derek Davis
(e-mail address removed)
Surely the scenario you give does make it soung a bad idea. I am not looking for a big mess later. It is just a way to organize GUI forms. Bracking class might not be a good idea (but still it is supported in full swing in vs2005) but organizing similer controls or GUIs is. It is happening for many years now, it is just that I am trying to find if it is possible in vs IDE. As one of the replies on this thread suggested how folders will work and I guess that solves my problem.

Thanks.
"carion1" <ddavis76 _at_ gmail _dot_ com> wrote in message I can see the frustration ahead. Walking into company abc and finding a crap ton of classes each spread across many files. I bet someone even comes up with some nifty naming convention for said files to easily (lol) keep track of what method is where (just say no). Not even solid gold meatballs could save that spaghetti. Please excuse me I just think this is a bad idea.

--

Derek Davis
(e-mail address removed)
I know this is in vs2005 but is there a way to

1- Divide class or move some helper methods on to another file and still be able to use in main file.

2- Is there a way I can move similer files under one folder under a project under a solution and still be able to use that code.

I tried both in my ways but did not work. Just wondering if possible.

Thanks,
Po
 
The partial classes in C# 2005 seem to be exactly what you you are looking
for. Therefore it seems to confirm that there is no designated way to do this
C# 2003.
So, you basically have your answer.
 
Back
Top