partial-classes

Partial Classes in C#

Are there are good uses of Partial Classes outside the webforms/winforms generated code scenarios? Or is this feature basically to support that? ...

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"; } } } A2.cs: private partial class A { void SomeFunction() { //trying to access this....

.NET partial class' accessibility over multiple files

If I have the core of a class defined in one file as "public partial" and I wish to create additions to this in another file, what is the difference between defining "public partial" again in my second file or just defining "partial"? What happens if I define "private partial" in my second file? ...

C#: Partial Classes & Web Services: Seperating form and functionality

Hi all, I am dabbling in the world of web services and I've been making a simple web service which mimics mathematical operations. Firstly it was simple, passing in two integers and then a binary operator would be applied to these (plus, minus etc) depending on the method called. Then I decided to make things a little more complex and ...

Accessing members of the other half of a partial class

I'm just learning to work with partial classes in VB.NET and VS2008. Specifically, I'm trying to extend a LINQ to SQL class that was automatically created by SqlMetal. The automatically generated class looks like this: Partial Public Class DataContext Inherits System.Data.Linq.DataContext ... <Table(Name:="dbo.Concessions")> ...

Override Default Constructor of Partial Class with Another Partial Class

I don't think this is possible, but if is then I need it :) I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008. The proxy output is partial classes. I want to override the default constructor that is generated. I would rather not modify the code since it is auto-generated. I tried making anoth...

Properties in partial class not appearing in Data Sources window!

Entity Framework has created the required partial classes. I can add these partial classes to the Data Sources window and the properties display as expected. However, if I extend any of the classes in a separate source file these properties do not appear in the Data Sources window even after a build and refresh. All properties in partia...

How do I use Read-Only properties defined in partial (Entity Framework) classes over ADO.Net Data Services

I have objects that are defined by the Entity Framework that I have then added additional methods and properties to via partial classes. I think I understand most of the limitations around doing this, but wanted to confirm something I am seeing (or hopefully learn what I need to do to make this work). I have a partial class that then h...

Detecting DataRow changes from within a partial class

Let's say I have an interface representing a domain object: public interface IFoo { Bar Bar { get; } } The Bar type is a family of objects, each of which has a slightly different schema. In the database, this is represented as XML (this is a mobile app, so it is simply nvarchar, not a true XML column). I have a generated DataSet ...

Best Practices: When not/to use partial classes.

I have been using the partial class modifier for some time in order to put helper classes in their own file. Today we got a new guy and he said that the last team he worked with didn't allow partial classes for this because modifying a helper class that is in a separate file would cause the main partial class file to get out of whack wi...

Entity Framework - how do I use the entity relationships in my extended classes?

I am trying to extend the partial classes that the entity framework creates so that I can more easily work with objects like in the code below (please let me know if there's a better or more exceptable way of doing this with the entity framework) Public Sub New(ByVal ProjectID As Integer) Dim proj As Project = (From p In db....

Using Partial classes for autogen code, how to setup filenaming etc?

Hi, I have a datalayer.cs file that was generated using a code gen tool. I am marking the class as a partial class, so I can create another file with my own hand written datalayer code. How should I name my files? Should I do it like this: /data/partial/datalayer.cs /data/datalayer.cs So when I run my codegenerator again, I just d...

Error using Nested insert_html partials in rails

So I have two nested partials with calls to insert_html. Basically each team has multiple players and I have an add player button and an add team button which each call a partial with the following helpers module TeamsHelper def add_team_link(name) link_to_function name do |page| page.insert_html :bottom, :teams, :parti...

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 + Stamper.Dispose.cs where Stamper.cs contains actual logic for stamping and Stamper.Dispose.cs that contains...

ASP.NET Additional Partial Classes

I have a huge code behind file for one of my ASP.NET pages. It would be easier to maintain the code if I could break it up into multiple partial classes. However this is not well documented for ASP.NET. I've learned that the additional partial classes must be moved into the App_Code folder. It seems that I need to use Protected WithEve...

Visual C#, Winforms, and Partial Class Madness

Hello, 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 default. The only exception being "*.Designer.cs" files. Generally speaking, this is...

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 { partial void InsertCourse(Course instance) // this definition copied from generated file ...

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 be shown as 2 seperate files in the Solution explorer. ...

Complementing the entity in ADO.net Entity Data Model

(Playing around with the MVC framework) I have created a ADO.net Entity Data Model. Now I'd like to extend it with some business logic, like creating functions returning subsets of the context. A partial class is created together with the Data Model, so I created a new file declaring a partial class like this: I placed a function in it ...

With partial classes, what controls order?

As discussed in http://stackoverflow.com/questions/431203/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 resulting order? That is, which file's properties comes ...