Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi everybody, I am currently stuck in this Class Library problem. I have a Class Library called ClsLib and is required to create a sub .cs file under a .cs file. For example,


. clsFile
. ClsLib.clsFile.(something)

I would appreciate if anyone would be able to help me with this. Thanks.
Posted

Still haven't made yourself quite clear. But I think this is what you want. Create a class library. Add 2 classes, giving them a name of "Class1.cs" and "Class2.cs". Close Visual Studio. Open the ".CSPROJ" file in notepad. Replace this line:
<Compile Include="Class2.cs" />

...with these three lines:
<Compile Include="Class2.cs">
    <DependentUpon>Class1.cs</DependentUpon>
</Compile>

Save and close the file. When you open the solution, "Class2.cs" will be listed under "Class1.cs". Keep in mind that you can name "Class1.cs" and "Class2.cs" whatever you want, but I used those simple examples so that the above example would be clear. Is this what you wanted?

Also, somebody made a macro to automate the above process. I haven't tried it, but if you want to, then see here.
 
Share this answer
 
v2
I don't really follow. Are you talking about nested classes?
 
Share this answer
 
So, are you saying you are trying to nest files in the solution explorer, like how it is done with Forms and their corresponding designer.cs files? Or, are you saying that your classes got nested and now you can't see them? Or something else? You need to be a little more clear. Please edit your original question to clarify. Stating what you are trying to accomplish and why you are unable to do so would be a good start.
 
Share this answer
 
See below the example.....
namespace MyCars
{
public class Car
{
// Aggregation uses instances of objects created outside of
// this class
protected Door FrontRight;
protected Door FrontLeft;
protected Door RearRight;
protected Door RearLeft;

// inner classes used to create objects that are intrinsically
// linked to the class Car
protected class Engine
{
public int horsePower;
}

protected class Battery
{
public int voltage;
}

// Composition uses instances of objects that are created as
// part of this object
protected Engine theEngine;
protected Battery theBattery;

public Car()
{
theEngine = new Engine();
theBattery = new Battery();
}
}

public class Door
{
public int position;
}
}
 
Share this answer
 
I don't know the purpose of having the nested file structure in your solutions explorer. And according to my knowledge, we can't create a nested class structure like that.

But if you want to create a super class called "clsFile" and create a subclass called "clsSubFile", we can use the following syntaxes for that.

public class clsFile
{

}

public class clsSubFile : clsFile
{

}
 
Share this answer
 
I don't think so. I am doing it relating to a Class Library. I want to show the classes on the Solution Explorer in Visual Studio as well.
 
Share this answer
 
Oh well, I guess I'm not explaining things clearly enough. For example, in my Class Library Application (ClsLib) I need to create two class files namely (clsFile & clsLib.clsFile.(something).


And so, when I create the first class file (clsFile), I need to create a sub-class file underneath clsFile. Thus, in Solution Explorer, I will have clsLib.clsFile.(something) created as a sub class under clsFile.


Sorry if I am still not making things clear enough.
 
Share this answer
 
Thanks aspdotnetdev. Yo've been of great help to me!
Sincere apologies and appreciation to all who had rendered their help :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900