partial-classes

ASP.Net MVC 3 ViewModel Data Annotations

自作多情 提交于 2019-11-28 21:17:39
问题 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 realise this is poor practice. For example: public class ViewModelTeam { public Team Team { get; set; } } My View might then have something like this @model UI.ViewModels.ViewModelTeam @Html.HiddenFor(model => model.Team.teamID) <div class="editor

C++ partial method specialization

末鹿安然 提交于 2019-11-28 07:12:54
问题 Is there a partial specialization for template class method? template <class A, class B> class C { void foo(); } it doesn't work to specialize it like this: template <class A> void C<A, CObject>::foo() {}; Any help? 回答1: If you are already have specialized class you could give different implementation of foo in specialized class: template<typename A, typename B> class C { public: void foo() { cout << "default" << endl; }; }; template<typename A> class C<A, CObject> { public: void foo() { cout

Partial classes in separate dlls

╄→尐↘猪︶ㄣ 提交于 2019-11-28 07:06:44
Is it possible to have two parts (same namespace, same class name) to a partial class in separate DLLs? From MSDN -Partial Classes and Methods : All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules. No. Partial classes are a purely language feature. When an assembly is compiled, the files are combined to create the type. It isn't possible to spread the files out into different assemblies. Depending on what you want to do, though, you might be able to use

Adding DataAnnontations to Generated Partial Classes

倖福魔咒の 提交于 2019-11-28 07:04:21
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 already defined" error. I think I might have seen an example a while ago of what I'm trying to do with

Override Default Constructor of Partial Class with Another Partial Class

拟墨画扇 提交于 2019-11-28 06:41:30
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 another partial class and redefining the default constructor, but that doesn't work. I then tried using the override and new keywords, but that doesn't work. I know I could inherit from the partial class, but that would mean I'd have to change all of our source code to

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

☆樱花仙子☆ 提交于 2019-11-28 01:50:55
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 attributed as SuperCool but I wish to do so in another file. Since I'm using partial classes, I can add new properties as follows. public partial class Hazaa { [SuperCool] public int Wheee { get; set; } } But can I attribute a property declared in the first sample by writing code in the latter? I doubt it's possible but I'll be glad to stand corrected.

A way to implement partial classes in java

僤鯓⒐⒋嵵緔 提交于 2019-11-27 21:31:53
问题 I have an interface that I want to implement in separate classes after doing a quick google search apparently, Java doesn't have partial classes. Is there a way that I can do this or am I stuck throwing all of my code into one class? Basically, I am trying to write a service. Some of the service methods really belong in their own class and seem kind of illogical in the same class. Here is an example of what I am trying to do. package com.upmc.esdm.messaging.epcd.service; import java.util.List

Should you use a partial class across projects?

我们两清 提交于 2019-11-27 15:26:11
I have a class library with all my database logic. My DAL/BLL. I have a few web projects which will use the same database and classes, so I thought it was a good idea to abstract the data layer into its own project. However, when it comes to adding functionality to classes for certain projects I want to add methods to certain classes. For example, my data layer has Product and SomeItem objects: // Data Access Layer project namespace DAL { public class Product { //implementation here } public class SomeItem { //implementation here } } In one project I want to add an interface that is used by

Naming Conventions For Partial Class Files

喜欢而已 提交于 2019-11-27 10:46:28
I'm generating the bulk of my ASP.NET MVC scaffolding code. All generated files are partial classes which use standard naming conventions. For example, my employee controller file is named EmployeeController.cs. If I wish to extend the EmployeeController with custom, non-generated logic, I create a second partial class file named EmployeeControllerCustom.cs. I separate the custom and generated logic into two different files so the next time I generate the EmployeeController my custom changes aren't overwritten. Adding the "Custom" suffix to the file name seems reasonable to me, but is there a

Can I define properties in partial classes, then mark them with attributes in another partial class?

天大地大妈咪最大 提交于 2019-11-27 10:43:29
Is there a way I can have a generated code file like so: public partial class A { public string a {get; set;} } and then in another file: public partial class A { [Attribute("etc")] public string a {get; set;} } So that I can have a class generated from the database and then use a non-generated file to mark it up? Dan Dumitru I've seen something like this done in an article by Scott Guthrie (near the end of it) - didn't try it myself, though. http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx [MetadataType(typeof(Person_Validation))] public partial class