Questions tagged [partial-methods]

In C#, a partial method has an optional implementation. Without an implementation, the compiler will remove the method and all calls to it.

In , partial methods are methods defined with the partial modifier.

Partial methods can be defined as part of a partial class or struct, and have an optional implementation. If there is no implementation in any of the parts of the class or struct, the compiler will remove this method and any calls to it.

References

28 questions
24
votes
3 answers

Partial Methods in C# Explanation

I am having a hard time understanding the usage of partial methods. Can you provide an example that doesn't have to do with LINQ or that sort of database things? Are partial methods the same things like when we are in the WinForms and coding behind…
Johnson
  • 401
  • 5
  • 14
19
votes
7 answers

C# Why can partial methods use ref, but not out?

Pretty straight forward. MSDN states that you can use ref, but not out for partial methods. I'm just curious as to the why? It was my understanding that when code is compiled, the partials are merged, so what is up with the restriction? Is there…
myermian
  • 31,823
  • 24
  • 123
  • 215
18
votes
5 answers

How are partial methods used in C# 3.0?

I have read about partial methods in the latest C# language specification, so I understand the principles, but I'm wondering how people are actually using them. Is there a particular design pattern that benefits from partial methods?
Eric Z Beard
  • 37,669
  • 27
  • 100
  • 145
12
votes
4 answers

Why you need partial methods in c#? Can events be used to achieve the same goal?

I was reading the book "Apress Pro LINQ: Language Integrated Query in C#" and I came across partial methods, but I really don't understand what is the need for them. I think the examples in the book (properties before and after change) can be…
Karim
  • 6,113
  • 18
  • 58
  • 83
9
votes
3 answers

Why partial methods can only have void return type?

what is the reason /logic/obstacle behind the fact that partial methods can only have void return type? thanks
pencilCake
  • 51,323
  • 85
  • 226
  • 363
6
votes
2 answers

Why it is possible to assign partial methods to delegates in spite of other constraints?

I know the title might not be totally clear, but I didn't want to make it too long. One thing boggles me when thinking about restrictions placed on partial methods. It seems to me that the rules are inconsistent. As you probably know: Partial…
Kapol
  • 6,383
  • 3
  • 21
  • 46
6
votes
2 answers

Why do partial methods support ref but not out parameters

I was reading up on partial methods since they will become a lot more important in C#-6 / Visual Studio 2013 update 2 in combination with Windows Universal Projects. While reading the documentation I read this weird limitation on the signature of…
Roy T.
  • 9,429
  • 2
  • 48
  • 70
6
votes
0 answers

Partial method implementation gives error "no defining declaration found for implementing declaration of partial method..."

I'm writing a Winforms project that needs a settings form. For that settings form, I want to have two modes, a basic and an advanced. I've written the code to make it change between these two, and to save time, I want to have the…
David Legg
  • 271
  • 1
  • 4
  • 12
5
votes
2 answers

How to add a partial method without an implementation using CodeDom

internal List createEventHooks() { string[] eventNames = new string[] { "OnUpdate", "OnInsert", "OnDelete", "OnSelect", "OnSelectAll" }; List eventHooks = new…
Chris McCall
  • 10,317
  • 8
  • 49
  • 80
5
votes
3 answers

Using reflection to check if a partial method has been implemented

Background I am using Linq to SQL and thus have a generated DBML file containing auto-generated classes. Part of the generation process creates partial methods for certain actions, and in my case the two methods I am interested in related to the…
musefan
  • 47,875
  • 21
  • 135
  • 185
4
votes
1 answer

How to use partial method in C# to extend existing implemetation

It would be great if this would work. Am I trying to implement my idea in the wrong way? I would like to use partial method, to be able to extend existing code, and simply plug in/out implementation of methods. Basically exactly what the reference…
DDan
  • 8,068
  • 5
  • 33
  • 52
4
votes
2 answers

How to code the partial extensions that Linq to SQL autogenerates?

I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework 3.5 SP1, in this case I extended the partial partial void UpdateMyTable(MyTable instance){ // Business logic // Validation rules, etc. } My problem is when I execute…
MrByte
  • 313
  • 1
  • 3
  • 9
3
votes
3 answers

How can I remove ASP.NET Designer.cs files?

I've worked on VS projects before where there is no .designer.cs files. Now I started a new project on a different computer and I can't get rid of designer.cs files. It's really annoying me. Do I really need it, how can I remove it? There must be a…
Adam Nathan
  • 160
  • 1
  • 7
2
votes
2 answers

generic partial methods in C#?

Partial classes and Partial methods states: Partial methods can be generic. Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one. Parameter and type parameter names do not have to be…
user17163459
2
votes
1 answer

What does "Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one" mean?

While reading about "partial methods" in the C# documentation, I found the following sentence: Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one. Can someone explains me with an…
DPM
  • 1,540
  • 2
  • 18
  • 40
1
2