473,695 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two questions about "partial classes"


Two question about the "partial classes" (in the next wersion of
..NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.
/Gomaw

Nov 15 '05 #1
9 2523
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Gomaw Beoyr" <Go*********@no .spam.please.no > wrote in message
news:Oz******** ******@TK2MSFTN GP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Partial classes are purely a compile-time construct, and all parts of the
class must be marked with partial. They aren't intended to be used to extend
system classes. I haven't thought about this deeply, but my guess is that
there could be some security issues in doing that, along with the problem of
possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.
Nov 15 '05 #2
Eric,

I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?

It seems you are adding a great deal of complexity
(and therefor potential for great abuse)
with very little return or benefit.

-c

"Eric Gunnerson [MS]" <er****@online. microsoft.com> wrote in message
news:u9******** *****@TK2MSFTNG P10.phx.gbl...
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights. "Gomaw Beoyr" <Go*********@no .spam.please.no > wrote in message
news:Oz******** ******@TK2MSFTN GP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Partial classes are purely a compile-time construct, and all parts of

the class must be marked with partial. They aren't intended to be used to extend system classes. I haven't thought about this deeply, but my guess is that there could be some security issues in doing that, along with the problem of possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.

Nov 15 '05 #3
I too am not sure if this is a good thing or not, but abuse comes very
commonly with everything(i really hope no one comes up with seriously
abusive ways to use generics, but you know as well as i do that as soon as
they come out publically there will be thousands of classes written with
them that doesn't need them), same as with all new features.
Anyway, in addition to chads comments, the problems this seems to solve
seems like something the IDE should handle more than the compiler.
I have to say, however, that i'd have rather seen an IDE that was capable of
analyzing the file, breaking the regions into virtual subsections(lik e
having a + in the treeview in solution explorer next to the file that drops
down into sub sections), properly decorated with class information, etc,
allowing for a developer to view the entire class, or subsections in a
virtual manner, without any distracting region labels, etc. without breaking
the files apart. If taken a step further it could potentially allow for far
greater flexibility than partial types would. Althought i'm sure that would
cause an increased amount of implementation complexity in the IDE (possibly
more than partial types adds to the compiler)

In a bit of defense, however, it would allow generators to (re)create entire
files without having to worry about wiping out user code, however why
merging the classes would have a benefit over inheriting from the generated
class is still a mystery to me.
"Chad Myers" <cm****@N0.SP.A M.austin.rr.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Eric,

I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?

It seems you are adding a great deal of complexity
(and therefor potential for great abuse)
with very little return or benefit.

-c

"Eric Gunnerson [MS]" <er****@online. microsoft.com> wrote in message
news:u9******** *****@TK2MSFTNG P10.phx.gbl...
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no

rights.
"Gomaw Beoyr" <Go*********@no .spam.please.no > wrote in message
news:Oz******** ******@TK2MSFTN GP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.


Partial classes are purely a compile-time construct, and all parts of

the
class must be marked with partial. They aren't intended to be used to

extend
system classes. I haven't thought about this deeply, but my guess is

that
there could be some security issues in doing that, along with the

problem of
possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.


Nov 15 '05 #4
Hi Chad,

|| I still don't get the point of partial classes.

Some reasons why I look forward to them:

Regions are useful, but when I have to play clicky-clicky all the
time to hide and reveal it gets to be a real pain.

I can put these-definitely-work methods into one file,
these-are-getting-there into another and work-in-progress in another.
It all cuts down the amount of hunting and scrolling.

Search and replace is easier (more predictable) with a smaller
text base.

In a big class there will be logically distinct sections. I'd be
happier with these in separate files.

In a team situation, two members can work on the same class.

In a team situation, partial class files may be made read-only to
force a developer to pause and consider, or even have to seek
permission.

And I'm sure I've got more reasons waiting to be discovered.

Regards,
Fergus
Nov 15 '05 #5
Hi Daniel,

I like your idea of the Explorer-style code window. Anything that
let's me see what I'm working on and hides the rest is welcome. I even
sometimes resent the single line that a hidden region takes (wastes) -
I'd like some other indicator (small, if not tiny).

But plenty of people don't use the IDE.

Regards,
Fergus
Nov 15 '05 #6
Chad Myers <cm****@N0.SP.A M.austin.rr.com > wrote:
I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?


Absolutely! I've seen a number of classes which are part autogenerated,
part handwritten - and not just GUIs. Keeping the autogenerated parts
of those classes separate means that a change to the autogeneration
process (or whatever) can regenerate the autogenerated part without
disturbing the other part at all. Every change in the handwritten part
of the code is guaranteed to be done by a developer, so it's more
likely to be an interesting part of the history (where some
autogeneration tools might generate subtly different but functionally
equivalent code in multiple runs, eg the order of variables may be
different - that kind of thing isn't worth looking at).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #7
Jon Skeet <sk***@pobox.co m> wrote:
Absolutely! I've seen a number of classes which are part autogenerated,
part handwritten - and not just GUIs. Keeping the autogenerated parts
of those classes separate means that a change to the autogeneration
process (or whatever) can regenerate the autogenerated part without
disturbing the other part at all. Every change in the handwritten part
of the code is guaranteed to be done by a developer, so it's more
likely to be an interesting part of the history (where some
autogeneration tools might generate subtly different but functionally
equivalent code in multiple runs, eg the order of variables may be
different - that kind of thing isn't worth looking at).


I've read two reasons in this thread that make some sense: 1) separating
out auto-generated code and 2) team development on a single class. I
could also understand code size management, but it hasn't been a problem
for me so far, and I suspect that a class that large should probably be
restructured. I'm not sure that any of these are so vitally important as
to require a change in the language.

But I think I am siding with the poster who voiced concern that the
feature will end up being abused, in ways we haven't envisioned. Take as
an example templates in C++. When they were first introduced, we thought
it was a nice way to make generic type-safe containers, and to avoid
having many overloaded functions of the same name (max(), for instance).
Now, C++ templates have grown into a complexity monster. I've used
templates for years, but I look at some of the code in boost or Loki, and
can only say "Huh?". I can't even read the stuff. I don't consider that
progress.

Part of the appeal of our "new" languages such as Java and C# is that
they got rid of the old-school mentality of complexity over usability.
Certainly not as satisfying to the ego, if you need that, but if you want
to write good, clean (and correct) code that both you and others can
understand, they were a great step in the right direction. As we have
seen with C and C++ over many years, abusing a feature cannot be
outlawed. The C preprocessor, templates, pointers and casts -- all
features that can be either used or abused, and which, mostly, are abused
by everyone simply because it's not illegal. It hardly matters that *I*,
as an individual developer, may not abuse them, because I don't work in a
vacuum and am constantly having to interface with code written by others,
including system libraries and SDKs as well as in-house code. And like a
disease, complexity infects everything it touches.

An additional benefit of that simplicity is the rapid growth of
programming aids and tools. Java has been around for a little while now,
and there are all kinds of programming tools that have sprung up. The
language is simple and clear enough that writing a code browser is not a
major undertaking requiring a team of 20 developers. C# is a little more
complex than Java, but still nowhere near C++ in complexity. Heck, I even
wrote a C# parser myself. It was more than an afternoon project on a
rainy day, but I did it. And I would never try writing a C++ parser!

Look: Visual Studio .NET 2002, right out of the gate, had immensely
better Class View and Intellisense than the same features for C++. Fast
and virtually bug-free. Same for the C# compiler. And yet, even in VS.NET
2003, after all these years of development, MS has not been able to get
Class View or the compiler to work correctly for C++ code. That should
tell us something. Will this be C# in 5 years?

I urge Microsoft not to turn C# and .NET into another COM embarrassment.
I know you have directives to churn out new features each year, but
please -- use caution, and focus on usability over complexity!

--
harry
Nov 15 '05 #8
Harry Bosch <no**@given.com > wrote:
I've read two reasons in this thread that make some sense: 1) separating
out auto-generated code and 2) team development on a single class. I
could also understand code size management, but it hasn't been a problem
for me so far, and I suspect that a class that large should probably be
restructured.
Agreed.
I'm not sure that any of these are so vitally important as
to require a change in the language.
It's only a slight (and non-breaking, as I understand it) change, which
at least makes it easier to bear.
But I think I am siding with the poster who voiced concern that the
feature will end up being abused, in ways we haven't envisioned.


Oh I'm certainly *concerned* about that - but not necessarily to the
point of thinking it's a bad idea.

Fortunately, it's a feature which is *very* easily policed - the team
leader can much more easily search for abuses of this (as it should
rarely be used at all) than of things like C++ templates. That's part
of the reason for my tentative support - abuse of it is obvious.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #9
Jon Skeet <sk***@pobox.co m> wrote:
It's only a slight (and non-breaking, as I understand it) change,
which at least makes it easier to bear.
Yes, non-breaking would make it agreeable :-) Good point.
Fortunately, it's a feature which is *very* easily policed - the team
leader can much more easily search for abuses of this (as it should
rarely be used at all) than of things like C++ templates. That's part
of the reason for my tentative support - abuse of it is obvious.


Also agreed. I think my rant was more towards language directions in
general, and really really not wanting C# to head in that direction. I
think we're in good shape, however.

--
harry
Nov 15 '05 #10

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

Similar topics

3
4797
by: TheLetti | last post by:
Hy! I've just downloaded the latest Java 2 SDK (j2sdk1.4.2_01). For my surprise in this version the servlet-classes are not integrated (e.g. the class javax.servlet). So I found all the servlet-classes I needed on the java.sun.com-Homepage and downloaded the javax.servlet-Package. (Maybe this file-description may help you understanding my problem:
0
2253
by: jb_in_marietta | last post by:
I have a Dot Net project that references a COM DLL called "Crypto.dll," which is registered on my machine. I added the reference via the "Add Reference" dialog in Visual Studio Dot Net, and I am successfully accessing methods in this DLL in some of my classes. "Interop.CRYPTOLib" is the name of the interop VS.NET created for me when I added the reference. Frequently, when I try to run my application, I get the error that follows.
3
2862
by: Phil Sherman | last post by:
What is the relationship between the snapshot elements: Log pages written Number write log IOs Number partial page log IOs There doesn't appear to be any information in my PDF System monitor guide or the online information center. When a COMMIT is issued; a log page containing updates must be written to disk before control is returned to the application program. This
5
3075
by: | last post by:
Hoping someone can help with a simple but puzzling problem. I have some code that I want to build as a class method. The code works fine when I embed it in Page_Load. But when I try to generalize the code into the method of a class I am trying to build, it gives me strange errors: "CS0103: The name 'Server' does not exist in the current context". (Server being a call to Server.MapPath.) I'm working in ASP.NET 2.0 and VS.NET 2005. ...
1
10411
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be sure I have a good understanding of this before I continue with my studies. Thanks in advance. Semper Fi
3
1839
by: Giggle Girl | last post by:
I have inherited some CSS from a former employee that has code like this: onmouseover="this.className='highlight_on standard_border'" where it appears to activate two different classes, "highlight_on" and "standard_border". Is this valid CSS?
169
9070
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
0
3531
by: Samuel R. Neff | last post by:
We're migrating our .NET 1.1 web application to .NET 3.5 and during conversion we clicked "Convert to Web Application" on the web project. The results from this conversion were inconsistent. 1. Many pages were not converted at all. They're still aspx and cs files with generated code inside the cs file and still no partial class implementation. 2. Designer classes empty. A few pages were converted to partial classes, but the...
0
876
by: AAaron123 | last post by:
Some of my partial classes end with "_aspx" and some do not. I made some changes with cut and paste and may have made some mistakes. I do use master pages. Do all partial classes normally end with "_aspx"?? Thanks
0
8619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8555
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9112
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8824
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8817
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5831
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.