base-class

JAXB Marshalling - extending an existing class

这一生的挚爱 提交于 2019-12-05 01:59:09
问题 I am in need of creating a series of Java objects via XML using JAXB that all extend a common base class that is already created (not using JAXB). For example, let's say I have following JAXB classes that I am trying to generate: Penguin.xml -> Penguin.java Robin.xml -> Robin.java Cardinal.xml -> Cardinal.java I already have an existing base class called Bird.java that I wish the three classes above to extend. What is the best way to do this? Thanks for your help! 回答1: That is very simple:

Erroneous private base class inaccessible?

拜拜、爱过 提交于 2019-12-04 23:24:26
问题 Compiling this code using g++ 4.2.1: struct S { }; template<typename T> struct ST { }; template<typename BaseType> class ref_count : private BaseType { }; template<typename RefCountType> class rep_base : public RefCountType { }; class wrap_rep : public rep_base<ref_count<S> > { typedef rep_base<ref_count<S> > base_type; // line 11 }; I get: bug.cpp:1: error: ‘struct S’ is inaccessible bug.cpp:11: error: within this context However, if I change the wrap_rep class to use ST : class wrap_rep :

Generic Entity Base Class

蓝咒 提交于 2019-12-04 15:47:12
I've just read a post about Generic Entity Base Classes. Simply and if I'm not wrong, the main idea in behind is collecting all generic, non-entity-spesific fields in one interface, than implement it in main entities. It's going to be a TL:DR; Let's see some code. This is the base entity interface and it's generic impementation to another interface public interface IEntity : IModifiableEntity { object Id { get; set; } DateTime CreatedDate { get; set; } DateTime? ModifiedDate { get; set; } string CreatedBy { get; set; } string ModifiedBy { get; set; } byte[] Version { get; set; } } public

How to override parameter defined in interface method with richer type?

不打扰是莪最后的温柔 提交于 2019-12-04 14:23:04
I have these: public class TennisPlayer { } public class RogerFederer : TennisPlayer { } public class RafaelNadal : TennisPlayer { } And then I have some classes with methods, like these: public abstract class Manager { protected abstract void ScheduleFriendlies(TennisPlayer player); } public class RafaelNadalManager : Manager { public void ScheduleFriendlies(RafaelNadal rn) { //throw new NotClayException(); } } public class RogerFedererManager : Manager { public void ScheduleFriendlies(RogerFederer rf) { //throw new NotGrassException(); } } //'RafaelNadalManager' does not implement inherited

ASP.NET CodeFileBaseClass attribute vs. inherit from System.Web.UI.Page

大憨熊 提交于 2019-12-04 09:06:20
I've just created a base class for my pages by inheriting from System.Web.UI.Page : public abstract class PageBase : System.Web.UI.Page { ... } When I noticed that you can also declare a base page in an ASP.NET view: <%@ Page Language="C#" CodeFileBaseClass="PageBase.cs" CodeFile="page.aspx.cs" Inherits="page" %> Can someone explain what the pros and cons of either method are? When would you use one over the other, or are they both the same? What happens if you used both at the same time? CodeFileBaseClass , CodeFile , Inherits work together with inheritance, not in place of inheritance. For

Constructor and Destructor Inheritance

旧时模样 提交于 2019-12-04 06:01:29
I believe Constructors and Destructors in base class cannot be inherited by derived classes of the base class. Is my understanding correct. Your understanding is correct. For example, if you have class Base { Base(int i) {} }; class Derived: public Base {}; Derived d(3); This will not compile because the Base constructor is not inherited. Note that default and copy constructor are created by the compiler if possible, and call the corresponding constructor of base classes, therefore for those constructors it looks as if those were inherited. Niels I think this is what you are looking for? You

How to Get Base Class Instance from a Derived Class

主宰稳场 提交于 2019-12-04 00:11:32
I don't know if this is possible, but I am trying to get the Base Class instance from a Derived Class. In C#, I can use the base keyword to access properties and methods of the Base Class (of course), but I want to use base itself. Attempting to do so results in a "Use of keyword 'base' is not valid in this context" error. Example Code public class SuperParent { public int SPID; public SuperParent() { } } public class SubChild : SuperParent { public SubChild(int pSPID) { base.SPID = pSPID; } public int BaseSPID { get { SuperParent sp = base; return sp.SPID; } } } If you're working with an

How to avoid error “Constructor on type 'MyType' not found” when inheriting a base class

孤街浪徒 提交于 2019-12-03 22:14:38
I have a Visual Studio 2010 Windows Forms app which includes a Form base class that other classes will inherit. The base class' constructor takes a parameter that the child classes will pass to the base class. Example: public partial class BaseForm : Form { public BaseForm(int number) { InitializeComponent(); } } public partial class ChildForm : BaseForm { public ChildForm(int number) : base(number) { InitializeComponent(); } } The problem that I'm running into is, when I attempt to open the ChildForm in VisualStudio's Design View mode, I receive the following error: Constructor on type

JAXB Marshalling - extending an existing class

好久不见. 提交于 2019-12-03 16:26:17
I am in need of creating a series of Java objects via XML using JAXB that all extend a common base class that is already created (not using JAXB). For example, let's say I have following JAXB classes that I am trying to generate: Penguin.xml -> Penguin.java Robin.xml -> Robin.java Cardinal.xml -> Cardinal.java I already have an existing base class called Bird.java that I wish the three classes above to extend. What is the best way to do this? Thanks for your help! That is very simple: you need to to create a JAXB binding file with following contents: <jaxb:bindings version="1.0" xmlns:jaxb=

Entity Framework 4.1 Code First: Get all Entities with a specific base class

假装没事ソ 提交于 2019-12-03 13:37:55
I have a DbContext with set up different DbSet<T> s with all types that derive from the same base class: public class Foo : Entity { } public class Bar : Entity { } MyDbContext : DbContext { public DbSet<Foo> Foos { get; set; } public DbSet<Bar> Bars { get; set; } } Is it possible to get all entities which have the Entity base class in one query, like: DbContext.Set<Entity>(); // doesn't work I tried to introduce an explicit DbSet<Entity> to the DbContext, but that results in one big table for all entities in the database. Additional question: If this works somehow, what about querying for