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
23
votes
1 answer

XML Commenting on partial classes/methods

Is there a standard way that the tools used to generate the API documents handle having XML Style comments on partial classes? Basically, how should one comment a partial class/method so that the resulting help documents aren't mangled? This…
myermian
  • 31,823
  • 24
  • 123
  • 215
22
votes
4 answers

Is it possible to add an attribute to a property in a partial class?

I don't think it's possible but since I haven't got a definite clarity from MSDN, I feel that it's best to ask. Suppose that we have a class as follows. public partial class Hazaa { public int Shazoo { get; set; } } Then, I'd like Shazoo to be…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
21
votes
9 answers

Why cant partial methods be public if the implementation is in the same assembly?

According to MSDN Documentation for partial classes : Partial methods are implicitly private So you can have this // Definition in file1.cs partial void Method1(); // Implementation in file2.cs partial void Method1() { // method body } But you…
Simon
  • 33,714
  • 21
  • 133
  • 202
21
votes
12 answers

Error with C# Partial classes

I am using partial classes to split some functionality between 2 files, but I am getting an error. What am I doing wrong? A1.cs: private partial class A { private string SomeProperty { get { return "SomeGeneratedString"; } } …
Adam Tegen
  • 25,378
  • 33
  • 125
  • 153
20
votes
2 answers

Is it possible to break an interface into 2 partial interfaces and implement it in 2 partial classes?

I am making fairly extensive and ongoing modifications to a third party product for my employer. One of the major considerations when implementing my code has been to segregate it as much as possible to make the integration of changes from the…
Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
18
votes
1 answer

ASP.Net MVC 3 ViewModel Data Annotations

I am developing an ASP.Net MVC 3 Web application with Entity Framework 4.1 and I am getting a bit confused with regards using Data Annotations for form validation. I always return a ViewModel to a View as opposed to passing the actual object as I…
tcode
  • 5,055
  • 19
  • 65
  • 124
18
votes
5 answers

Is there a way to do partial classes in Java (like C#)?

C# has this great concept where a class can be spread across multiple .cs files. This works great where you want a single object (member variables that all the code needs) but there's a ton of code. You can then spread this code out by functionality…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
18
votes
2 answers

Prevent DebuggerStepThroughAttribute from applying to my non-xsd-generated partial class?

I used the xsd.exe tool to generate a class based on my xml schema. It created a public partial class with DebuggerStepThroughAttribute. Well, I created another partial class file for this class to write my custom code and want to be able to…
Lyndal
  • 371
  • 1
  • 3
  • 8
17
votes
1 answer

Partial classes and access modifier issue

According to MSDN Documentation for partial classes : All the parts must have the same accessibility, such as public, private, and so on. but if you create a WindowsForm application, you will have the default Form class in two partial classes. The…
Naser Asadi
  • 1,153
  • 18
  • 35
17
votes
5 answers

C# Partial Classes

I currently have a solution with multiple projects that mostly use the same classes. As a result, it appeared to me that it would be a good idea to add a class library containing these classes in the solution instead of repeating the class in each…
Andrew Keller
  • 3,198
  • 5
  • 36
  • 51
15
votes
4 answers

Naming convention for partial classes file names?

If I have partial classes in C#, what should the file names be? The class is called partial class Logic and would exist out of two or maybe three separate files.
Simon Verbeke
  • 2,905
  • 8
  • 36
  • 55
15
votes
2 answers

How to add data annotations to partial class?

I have an auto generated class with a property on it. I want to add some data annotations to that property in another partial class of the same type. How would I do that? namespace MyApp.BusinessObjects { [DataContract(IsReference = true)] …
O.O
  • 11,077
  • 18
  • 94
  • 182
15
votes
4 answers

WinForm partial classes

I have a WinForm project that contains a form called MainUI. You can see that the automatically generated partial class shows up as a node under MainUI.cs. Is there a way to "move" my self created partial class MainUI.Other.cs under MainUI.cs so…
nivlam
  • 3,223
  • 4
  • 30
  • 39
14
votes
5 answers

Access class fields from partial class

I'm currently in a scenario in which I have to make use of partial classes. In this partial class I have a few methods that need to address fields in the other class. for example Edit: I'm sorry: the first class is already declared partial! public…
Pepijn Olivier
  • 927
  • 1
  • 18
  • 32
14
votes
1 answer

partial classes/partial class file

In C# .net there is a provision to have two different class files and make them a single class using the keyword partial keyword.this helps it to keep [for ex]UI and logic seperate. of course we can have two classes to achieve this one for UI and…
Ravisha
  • 3,261
  • 9
  • 39
  • 66
1
2
3
29 30