i everybody, I am required to find out if the following is a standard practice to create a subclass.

Take for instance, I have to create a class library (ClLib) with 2 classes using Visual Studio: Class1.cs & Class2.cs.

Next, I open up the .CSPROJ file of ClLib and modify the following line:

<Compile Include="Class2.cs" />

to become

<Compile Include="Class2.cs" >
       <DependentUpon> Class1.cs </DependentUpon>

Can any kind soul help me solve this question? Your help would be greatly appreciated!

Edited 6 Years Ago by blur_guava: n/a

Why don't you just create a class in the designer and let the IDE/compiler handle it? I have never modified a project file like you're talking about

Why don't you just create a class in the designer and let the IDE/compiler handle it? I have never modified a project file like you're talking about

could you please elaborate? I am a newbie in class library.

How about you tell us what your problem is? Why are you trying to modify your .csproj? Will something not compile? Can you upload a sample? Where did you read about modifying your project file like this?

How about you tell us what your problem is? Why are you trying to modify your .csproj? Will something not compile? Can you upload a sample? Where did you read about modifying your project file like this?

Hi there, I need to do a project, and my supervisor has requested me to create a subclass within a class library. Right now, I can only create a subclass by editing the .csproj file. I know it's not a feasible idea, but I cannot find any other ways to create it. Besides, I need to find out if my method is a standard practice, and if it is not a standard practice, I would need to know the correct method of doing it.

I have gotten my reference from this website: http://www.delarou.net/weblog/2006/11/21/VisualStudioNETMacroForNestingProjectItems.aspx

The URL you provided looks like its showing you how to alter how Visual Studio organizes its project files -- but I think that is irrelevant as far as how the code actually functions. That will probably also cause issues when you try to upgrade the project to a new version of Visual Studio :)

I have no idea what a subclass is. Do you mean a child class? Perhaps something like this: ?

public class MainClass
  {
    public MainClass() { }
  }
  public class SubClass : MainClass
  {
    public SubClass()
      : base()
    {
    }
  }

I find it odd that you would be given a task to implement a subclass. Normally my bosses have given me a task and don't care so much how I go about it -- "ie fix this, add this functionality, and remove this option"

The URL you provided looks like its showing you how to alter how Visual Studio organizes its project files -- but I think that is irrelevant as far as how the code actually functions. That will probably also cause issues when you try to upgrade the project to a new version of Visual Studio :)

I have no idea what a subclass is. Do you mean a child class? Perhaps something like this: ?

public class MainClass
  {
    public MainClass() { }
  }
  public class SubClass : MainClass
  {
    public SubClass()
      : base()
    {
    }
  }

I find it odd that you would be given a task to implement a subclass. Normally my bosses have given me a task and don't care so much how I go about it -- "ie fix this, add this functionality, and remove this option"

yes, this is what i am referring to. Anyway, do you know how I can show Class 2 (or in your example, SubClass) to be indented under Class1 (or MainClass) in Visual Studio Solution Explorer?

Most people don't do that but the URL you posted shows how to do that. I either stick them in the same file if they're small and simple code classes .. or I use two files. You can right click on a class to "Find All References" so you can find the child classes, or you can hit F12 on the parent class definition to navigate to the other class. That is easy enough for me.

Most people don't do that but the URL you posted shows how to do that. I either stick them in the same file if they're small and simple code classes .. or I use two files. You can right click on a class to "Find All References" so you can find the child classes, or you can hit F12 on the parent class definition to navigate to the other class. That is easy enough for me.

I've tried to right-click/F12 the class already but to no avail. I am using Visual Studio 2008 Class Library.

This article has been dead for over six months. Start a new discussion instead.