partial-classes

Partial Class vs Extension Method

强颜欢笑 提交于 2019-12-20 09:33:08
问题 I dont have much experience of using these 2 ways to extend a class or create extension methods against a class. By looking others work, I have a question here. I saw people using a parital class to extend an entity class in a project. Meanwhile, in the same project, there is another folder containing a lot extension methods to the entity class. Is it right to do so? I mean these 2 ways both work well. Could you give me some real practice how to pick one from them when I want extend a class?

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

允我心安 提交于 2019-12-19 22:01:42
问题 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)) { var prop = GetType().GetProperty(key); if (prop == null) return null; return prop.GetValue(this, null) as string; } object value = Fields[key]; return value as string; } set { var property = GetType().GetProperty(key); if (property == null) { Fields[key] = value; } else { property.SetValue(this, value, null

Where to put common interface methods when dealing with partial classes, inheritance, and Visual Studio Generated Code

℡╲_俬逩灬. 提交于 2019-12-19 11:44:36
问题 Consider this situation: We have two classes generated by Visual Studio, for example Typed Dataset Rows. These classes derive from a common base class which we cannot change. We cannot change the class these child classes derive from, but they are generated as partial classes so we can extend them. Now we decide to implement an interface for these two classes which define some common methods, but the methods are going to be implemented exactly the same way in both classes. Where is the best

If a partial class inherits from a class then all other partial classes with the same name should also inherit the same base class?

不想你离开。 提交于 2019-12-18 18:41:51
问题 I have a class in Model in my MVC project like this. public partial class Manager : Employee { public string Name {get;set;} public int Age {get;set;} } And this class I have in App_Code folder in the same project. Now I want to know whether my this class is also need to get inherit from the Employee class or Not? public partial class Manager { public void SaveEmployee(); } I have to do this because my client want me to move all the methods in App_Code folder which are dealing with database.

WinForm partial classes

无人久伴 提交于 2019-12-18 12:57:09
问题 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 that it'll show as another node? 回答1: Close the solution in Visual Studio, and open your .csproj file in a text editor. Find MainUI.Other.cs, and add the following XML element: <Compile Include="MainUI.Other.cs"> <SubType>Form</SubType>

EF 4, how to add partial classes

南笙酒味 提交于 2019-12-18 05:00:26
问题 I needed to extend my EF partial classes, because I want to add some functionality to able to use Oracle's sequences , however I really don't know how to use this partial class thing, I made a seperate .cs file and name it as one of my auto-generated classes as follows: namespace GlassStoreDAL { public partial class CAR { private int _sequences; public int sequences { get { return _sequences; } set { _sequences = value; } } } } Now I assumed that, on my BLL - which references GlassStoreDAL -

partial classes/partial class file

爱⌒轻易说出口 提交于 2019-12-17 18:28:36
问题 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 other for logic. Can this be achieved in java some how? 回答1: On source file splitting No. Java source codes can not be split across multiple files. From the Wikipedia article Comparison of Java and C Sharp The Sun Microsystems Java compiler requires

Adding DataAnnontations to Generated Partial Classes

蹲街弑〆低调 提交于 2019-12-17 18:24:41
问题 I have a Subsonic3 Active Record generated partial User class which I've extended on with some methods in a separate partial class. I would like to know if it is possible to add Data Annotations to the member properties on one partial class where it's declared on the other Subsonic Generated one I tried this. public partial class User { [DataType(DataType.EmailAddress, ErrorMessage = "Please enter an email address")] public string Email { get; set; } ... } That examples gives the "Member is

EF 5 Model First Partial Class Custom Constructor How To?

余生颓废 提交于 2019-12-17 12:19:41
问题 EF has generated for me some partial classes, each with a constructor, but it says not to touch them (example below), now if I make my own secondary partial class and I want to have a constructor that automatically sets some of the fields how do I do so as it would conflict? //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your

Is it possible to have two partial classes in different assemblies represent the same class?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 04:27:13
问题 I have a class called 'Article' in a project called 'MyProject.Data', which acts as the data layer for my web application. I have a separate project called 'MyProject.Admin', which is a web-based admin system for viewing/editing the data, and was build using ASP.NET Dynamic Data. Basically I want to extend the Article class, using a partial class, so that I can augment one of its properties with a "UIHint" extender, which will allow me to replace the normal multi-line textbox with an FCKEdit