Questions tagged [partial-classes]

With this keyword classes can be split into multiple definitions, but it compiles into one class.

With this keyword, classes can be split into multiple (mostly two) definitions, but the code compiles into one run-time class.

References

441 questions
9
votes
8 answers

What are the benefits to using a partial class as opposed to an abstract one?

I have been reading Programming Microsoft® Visual C#® 2008: The Language to get a better understanding of C# and what can be done with it. I came across partial classes which I had already encountered from ASP.Net's Page class. To me it seems that…
uriDium
  • 13,110
  • 20
  • 78
  • 138
9
votes
5 answers

.NET Partial Classes vs. Inheritance

Okay, so we have a utility here in-house that generates business-model classes from our database tables and views, similar to (but not quite exactly like) an ORM. In maintaining it, it occurred to me that the data in the schemas isn't likely going…
Mike Hofer
  • 16,477
  • 11
  • 74
  • 110
8
votes
7 answers

LINQ to SQL - Compile error when extending data context with partial class and methods

I am trying to use the Extensibility Method Definitions from my datacontext.designer.cs file to do some validation. So I created a new file and added this code: public partial class LawEnforcementDataContext : System.Data.Linq.DataContext { …
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
8
votes
4 answers

Interface method return type to be class that implements the interface

I'm having trouble getting my head around interfaces. After trawling through similar questions on here, I've come up with the following interface, for defining the CRUD operations required for all my classes: public interface IData { IData
Lazlow
  • 3,241
  • 3
  • 21
  • 13
8
votes
1 answer

Placement of extended partial classes in entity framework

Since partial classes have to be in the same namespace is my only option to place them in the same directy as my .edmx? If this is the case I am assuming the file name always has to be different. Also, is there anything additional that I have to do…
JTunney
  • 914
  • 1
  • 15
  • 46
8
votes
4 answers

Partial classes in different namespace are not being recognized correctly

I have a partial class that is split over two namespaces. The problem is that if I have an interface implemented on one of the partials, it is not recognized on the counterpart partial class. For example, I would expect the below to return true for…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
7
votes
2 answers

Serializable partial classes

I have the following VB.NET class definition: Partial Public Class Customers End Class Inside another file I have the same thing (with different methods and variables of course). When I compile, I get the following error: Attribute…
Icemanind
  • 47,519
  • 50
  • 171
  • 296
7
votes
3 answers

Partial class spanning assemblies

In my framework project I have a class that represents tabs in a content management system. In some framewrok implementations it is desirable to extend this class with defintions of tabs that are specific to that implementation. I had though to do…
Jason
  • 3,599
  • 10
  • 37
  • 52
7
votes
1 answer

Form designer breaks on generic abstract UserControl

I have a generic abstract UserControl class, SensorControl, which I want all my sensor control panels to inherit from. The problem When attempting to design the EthernetSensorControl (one of my inherited UserControl forms, from within Visual Studio,…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
7
votes
2 answers

Merge multiple .NET binaries together?

I want to program something in both C# and F#. I have partial classes and i would like to define F# methods in a few of them. I get the issue that a partial class can not be spanned across 2 DLLs. Is there a way i can merged them? I prefer a free…
user34537
7
votes
1 answer

NUnit, TestDriven.Net: Duplicate test results with partial test classes

I just discovered that I was getting twice the number of tests run that I should've been getting. Discovered it when a test broke and I got two identical test failures. Same test, same everything. Got me quite confused, but managed to narrow it down…
Svish
  • 152,914
  • 173
  • 462
  • 620
7
votes
5 answers

Why are aspx code-behind files declared as partial classes?

Why is the code behind a partial class for aspx pages?
andrewWinn
  • 1,786
  • 2
  • 14
  • 28
7
votes
3 answers

Adding DataAnnontations to Generated Partial Classes

I have a Subsonic3 Active Record generated partial User class which I've extended on with some methods in a separate partial class. I would like to know if it is possible to add Data Annotations to the member properties on one partial class where…
Naz
  • 1,793
  • 2
  • 13
  • 25
6
votes
3 answers

ASP.NET Dynamic Data not seeing partial metadata "buddy" class

I have an ASP.NET 4 Dynamic Data web site that is running against a fairly simple set of database tables, exposed through an Entity Framework model in another assembly. I don't want to scaffold all of the tables in the EF model, so in my global.asax…
Matt Peterson
  • 5,169
  • 4
  • 32
  • 34
6
votes
4 answers

How to combine a Partial Class Object in C#?

I defined a class: public class Sample{ public string name {get;set;} public int price {get;set} } Then Sample sampleA = new Sample(); sampleA.name = "test"; Sample sampleB = new Sample(); sampleB.price = 100; I do this because I…
Eric Yin
  • 8,737
  • 19
  • 77
  • 118