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

Access custom property in Entity Class

I'm new to Entity Framework 4.1, and I have pretty much the same problem as this guy: Adding A Custom Property To Entity Framework? However, when I add a custom read-only property to my Entity using partial classes, I'm unable to access it as a…
2
votes
2 answers

How do I remove format from Linq property?

I´m building a Windows Forms aplication using LINQ to SQL. I´m using the auto generated code from the dbml file. Visual studio generated this code for the CNPJ property from my…
Fabio
  • 1,037
  • 1
  • 10
  • 22
2
votes
1 answer

TypeScript Recursive Partial confused when Classes share a property name

I've been using a Conditional Type in TypeScript to create a Recursive Partial. The issue I'm having is hard to explain without an example, so please see the code below (note: my particular use case is more complex, but the example illustrates the…
FTLPhysicsGuy
  • 1,035
  • 1
  • 11
  • 23
2
votes
0 answers

'InvalidOperationException: Multiple constructors accepting all given argument types err..' error and ActivatorUtilitiesConstructor attribute was used

I have two partial class files for the Client class. Client is registered with DI in .NET 6. I am getting an error: InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'xxxx.Client'. There…
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
2
votes
4 answers

Extending c# code with separate assembly

I have some extra functionality i need to add which includes adding a new property to an object and extending methods in another class that handles this object. I'm dealing with source code of a product (in C# 2.0) we use which i really don't want…
degero
  • 23
  • 1
  • 3
2
votes
1 answer

Is it possible to add more documentation to existing methods or classes in C#?

Suppose I am developing a C# library targeting two different platforms (lets say, WinForms and Blazor). One way to structure the code is to have a "core" set of common files that are partial classes, so that I can add platform-specific code in…
Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
2
votes
1 answer

Inherited base class that inherits ComponentBase in partial class gives error

I am working with a something.razor file and a code behind Something.razor.cs file. My partial class inherits from SomethingBase which itself inherits from ComponentBase. This however gives errors CS0115 .buildrendertree(rendertreebuilder)': no…
Power5000
  • 23
  • 2
2
votes
0 answers

Using private static members across partial classes

I have partial classes with static readonly fields, and in one of the partial classes I'm creating a static readonly list of all the static readonly members. For some reason, the list ends up with the correct numbers of entries, but all the entries…
devklick
  • 2,000
  • 3
  • 30
  • 47
2
votes
3 answers

Visual C#, Winforms, and Partial Class Madness

I haven't done much work with .NET, so forgive me if this has a trivial solution. The "problem" (more of an annoyance, really) is that the VC# IDE opens all files that have a class which inherits from System.Windows.Forms.Form in design-view, by…
PSIG_PTR
2
votes
3 answers

Variable scope at the same source file in partial classes

Is there anyway to reuse a method/variable name in partial classes? Something like internal which defines a variable scope at assembly level but this time at source file level. So we can use the same name in another code file and that variable is…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
2
votes
4 answers

extend class in c# with properties

I use Entity framework 6 (database first) in my mvc project. The database has a table called User which has columns like name, adress, email. In my project I therefore have the User.cs class auto generated in my project. I need to extend that user…
MTplus
  • 2,077
  • 4
  • 34
  • 51
2
votes
3 answers

Partial Class is created in new project

Whenever i open any new project in Visual Studio, a partial class is created. I need only a simple class as i need to practice OOPS concepts. How to create a new class or modify an existing partial class? I might sound stupid! :-) thanks!
xorpower
  • 17,975
  • 51
  • 129
  • 180
2
votes
8 answers

Should I separate Dispose logic into a partial class file?

While refactoring some C# classes, I've run into classes that implement IDisposable. Without thinking, I have created partial class files for each class that implements IDisposable interface. E.g.) For Stamper.cs -> Stamper.cs +…
dance2die
  • 35,807
  • 39
  • 131
  • 194
2
votes
2 answers

Break down form code behind WinForms

In my latest WinForms Project, the code behind for my Main form has started to become too large and difficult to read. In other posts that I have read through, I have seen suggestions that say to create another class that is a partial class of your…
2
votes
0 answers

Create method with refactor shortcut, is there a way to chose between partial or non partial target?

So basically, I have a tool that I designed, that generates some code based on the model, and pastes this code automatically inside the .partial classes, on this approach, .partial is used for generated code, and his normal class is used for my…