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
5
votes
3 answers

Using "partial" on a generic class

I am using a generic class called ViewModelCollection which handles a lists of ViewModels and delivers standard add() and delete() commands. Now I'm wondering if I can "extend" this class using the partial construct for a certain…
Michael Hilus
  • 1,647
  • 2
  • 21
  • 42
5
votes
2 answers

Adding attributes to properties in the Linq2Sql DBML

We are working with a database containing metadata on all database tables and fields used in our applications. From this metadata, we generate code that contains partial classes, extending our Linq2Sql entities. We had the idea of adding an…
Joachim VR
  • 2,320
  • 1
  • 15
  • 24
5
votes
3 answers

Java: Is there a way to put nested classes in a separate file?

I have a Java class that is about 4,000 lines long (lots of methods). This class then uses about 200 small classes that only it needs, so another 4,000 lines of code. If this was C# I would put those other in a partial class file so different file,…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
5
votes
1 answer

How to make user control partial classes aware of controls declared in the base class?

Do we have to do something special to have ASP.NET partial classes aware of controls that are declared in our user control's base classes? The partial classes keep generating declarations for controls in the base class which mean the controls in the…
Helephant
  • 16,738
  • 8
  • 39
  • 36
5
votes
4 answers

When should I use the Partial keyword?

I was reading the MSDN article on the Partial keyword, and this part caught my eye: The partial keyword indicates that other parts of the class, struct, or interface can be defined in the namespace. All the parts must use the partial keyword.…
Kyle Baran
  • 1,793
  • 2
  • 15
  • 30
5
votes
1 answer

member names cannot be the same as their enclosing type with partial class

I have defined a partial class with a property like this: public partial class Item{ public string this[string key] { get { if (Fields == null) return null; if (!Fields.ContainsKey(key)) …
espvar
  • 1,045
  • 5
  • 16
  • 28
5
votes
1 answer

How can I use attributes on a property defined in the other half of a partial class?

I have an autogenerated class from importing a web service containing something like this (abbreviated): [System.Runtime.Serialization.DataMemberAttribute()] public System.DateTime StartDate { get { return this.StartDateField; …
Abel
  • 56,041
  • 24
  • 146
  • 247
4
votes
3 answers

How do I view the rest of a partial class in a silverlight project?

So this is driving me nuts that I cannot see rest of the MainPage partial class in the MainPage.xaml.cs of my silverlight application. I'm no longer having any coding issues, but is there a way to view it? I want to see the other partial class(es).…
LLL
  • 1,085
  • 8
  • 16
4
votes
4 answers

Implementation of interface in C++

I need little help with inheritance in C++. I have code with same structure like this: class IBase { public: virtual long Dimensions() = 0; }; class IShape : public IBase { virtual long Area() = 0; }; class Rectangle : public IShape …
zdenek
  • 97
  • 1
  • 9
4
votes
2 answers

entity framework 4.1 partial class initialisation

In entity Framework 4.1 database first, there is a constructor in the generated c# class, so where can I do my partial class custom initialisation ?
tahir
  • 1,016
  • 1
  • 11
  • 21
4
votes
2 answers

Roslyn analyzer: Is class marked as partial

Is there a way to find out whether class is partial inside Roslyn analyzer? There is a PartialImplementationPart in IMethodSymbol, but nothing similar for INamedTypeSymbol. I'm writing a Source Generator, and I want to generate second part of the…
4
votes
3 answers

What controls XML serialization order of C# partial classes?

As discussed in Does the order of fields in C# matter?, the order of serializable properties affects, among other things, XmlSerializer output. But if fields are in 2 files (using partial classes), does anyone know what in fact controls the…
Eric Hirst
4
votes
1 answer

Add [IgnoreDataMemeber] to specific properties in a generated partial class

I have an Entity Framework POCO class that is generated by a T4 Template. I am planning to use the generated class as my data contract. However, it has a few properties that don't need to be in the contract. For example I have a property called…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
4
votes
2 answers

How do you test for a renamed partial method?

I'm using Linq to SQL, which generates partial classes and partial methods. You then extend that generated code by implementing your your customizations manually in another partial class. One of the hooks L2S gives you is the ability to implement…
mattmc3
  • 17,595
  • 7
  • 83
  • 103
4
votes
3 answers

Partial Class - Visual Studio 2008

Is there a possibility to create partial classes that are grouped in the Solution Explorer like VS does it with code behind classes (eg. Default.aspx and Default.aspx.cs). I would like to create MyClass.cs and MyClass.partial.cs and they should not…
chbu
  • 985
  • 1
  • 8
  • 18