Re: How do I create partial class to be nested under the main class file?
- From: "Joseph Geretz" <jgeretz@xxxxxxxxxx>
- Date: Wed, 28 Mar 2007 22:42:15 -0400
However, this is going to be VERY cumbersome if we need to do this
manually for all such partial classes which we create. Isn't there any way
to do this via the IDE, without having to resort to manually editing the
.csproj file in NotePad?
I guess not :-(
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=66418&SiteID=1
Pity.
- Joe Geretz -
"Joseph Geretz" <jgeretz@xxxxxxxxxx> wrote in message
news:%23UxatCYcHHA.3960@xxxxxxxxxxxxxxxxxxxxxxx
By editing the .csproj file I was able to achive the desired goal. I
changed:
<Compile Include="Form1.Interface.cs">
<SubType>Form</SubType>
</Compile>
to
<Compile Include="Form1.Interface.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
which is equivalent to the definition which I found for Form1.Designer.cs.
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
Having done this, Form1.Interface.cs now behaves exactly like
Form1.Designer.cs.
However, this is going to be VERY cumbersome if we need to do this
manually for all such partial classes which we create. Isn't there any way
to do this via the IDE, without having to resort to manually editing the
.csproj file in NotePad?
Thanks!
- Joseph Geretz -
"Joseph Geretz" <jgeretz@xxxxxxxxxx> wrote in message
news:ey1s8iWcHHA.3648@xxxxxxxxxxxxxxxxxxxxxxx
When I create a Form, the VB IDE creates the following files in the
following hierarchy:
Form1.cs
Form1.Designer.cs
Form1.resx
Both Form1.cs and Form1.Designer.cs are partial implementations of a
single physical class definition. The VB IDE properly recognizes Form1.cs
as a Form (i.e. double-clicking opens the Form designer). It also
recognizes Form1.Designer.cs as additional code implementation. It
properly nests this class file under Form1.cs and double-clicking the
file in the IDE opens to a code window, rather than a Form design window.
So far so good.
I'd like to extend the Form interface with a bunch of my own methods. So
I create a new class, Form1.Interface.cs, defined as follows:
partial class Form1
{
internal void DoThis()
{
}
internal void DoThat()
{
}
I'd like Form1.Interface.cs to behave just as Form1.Designer.cs does.
That is, I'd like this class to be nested beneath Form1.cs to make it
obvious that Form1.Interface.cs is a partial class addition to the
partial class defined in Form1.cs. I'd also like this class to open in
the IDE just as Form1.Designer.cs does; that is, double-clicking this
module should open a code window, not a Form design window.
But I can't get either of these to happen. My module Form1.Interface.cs
is treated by the IDE as though it is a Form. It doesn't appear nested
under Form1.cs and double-clicking it opens a Form design windows which
is totally inappropriate since this module is not intended to implement
any visual form elements at all!
(BTW, the compiler properly aggregates this into a single Form1 class
implementation. So there's no problem as far logical software
construction is concerned. However, it would be nice if I could get the
IDE to recognize the relationship between Form1.cs and Form1.Interface.cs
and to properly deal with this relationship (i.e. nesting and default
open action) just as it does with Form1.cs and Form1.Designer.cs.)
What am I doing wrong?
Thanks for your help!
- Joseph Geretz -
.
- References:
- How do I create partial class to be nested under the main class file?
- From: Joseph Geretz
- Re: How do I create partial class to be nested under the main class file?
- From: Joseph Geretz
- How do I create partial class to be nested under the main class file?
- Prev by Date: Re: Delegates/events
- Next by Date: Re: What Impact Do Static HashTables and Classes have on the CPU?
- Previous by thread: Re: How do I create partial class to be nested under the main class file?
- Next by thread: .NET Security
- Index(es):
Relevant Pages
|