base-class

C# private (hidden) base class

对着背影说爱祢 提交于 2019-12-23 07:25:55
问题 Is it possible to make a C# base class accessible only within the library assembly it's compiled into, while making other subclasses that inherit from it public? For example: using System.IO; class BaseOutput: Stream // Hidden base class { protected BaseOutput(Stream o) { ... } ...lots of common methods... } public class MyOutput: BaseOutput // Public subclass { public BaseOutput(Stream o): base(o) { ... } public override int Write(int b) { ... } } Here I'd like the BaseOutput class to be

Access “this” pointer of concrete class from interface

不羁岁月 提交于 2019-12-22 19:13:08
问题 After writing a test, I determined that the this pointer in an interface is not equal to the this pointer of the concrete class, meaning I can't just use a C-style cast on it. class AbstractBase {...}; class AnInterface { public: AnInterface() {...} // need AbstractBase * here ~virtual AnInterface() {...} // and here }; class Concrete : public AbstractBase, public AnInterface {}; My interface needs a base class pointer to the concrete class inheriting it in the constructor and destructor in

Several activities using same listener

我是研究僧i 提交于 2019-12-22 18:34:52
问题 I got 4 activites that all include a xml-footer which contains 4 buttons (one for each activity). I would now like to setup onclicklisteners to these buttons (it's a self made menu in the footer). The question is, how do I use listeners so that I can reuse code? I have two ideas: Create a class that implements onclicklistener and in every activity i would get the buttons and then create a new instance of the listener class and do button.setOnClickListener(onClickListener) The problem is that

How to represent calling base class method in overridden method?

不想你离开。 提交于 2019-12-22 09:56:40
问题 I have a child class which wants to add more functionality to a base class function, how can I represent that it also does the base class function not just the newly added functionality? 回答1: Interesting question. I tried that with Enterprise Architect. It did let me select the parent's operation but the display in the diagram did not change. It seems like you need to use notes for that: As you can see Class2 inherits from Class1 . The SD shows a call to Class2 's operation a() . The call to

Casting List of derived class to List of base class still returning objects of derived class

北慕城南 提交于 2019-12-22 07:55:59
问题 I have the following code: public class BaseClass { public string A { get; set; } } public class DerivedClass : BaseClass { public string B { get; set; } } List<DerivedClass> _derivedClass = new List<DerivedClass>() { new DerivedClass() { A = "test1", B = "test2" } }; List<BaseClass> _baseClass = _derivedClass.Cast<BaseClass>.ToList(); The code compiles without any error, however, I expected _baseClass to only contain Property A (object of type BaseClass ), but it's return both A and B

Non-testable base class extending PHPUnit_Framework_TestCase

馋奶兔 提交于 2019-12-22 01:23:48
问题 Summary How can I create a base class that extends PHPUnit_Framework_TestCase and use that for subclassing actual test cases, without having the base class itself tested by PHPUnit? Further explanation I have a series of related test cases for which I have created a base class that contains some common tests to be inherited by all test cases: BaseClass_TestCase.php: class BaseClass_TestCase extends PHPUnit_Framework_TestCase { function test_common() { // Test that should be run for all

In .NET, can you use reflection to get all non-inherited methods of a class?

梦想与她 提交于 2019-12-21 06:57:28
问题 Because of this issue here, I'm trying to write a custom JsonConverter that handles cases where you subclass a list or a collection, then add extra properties to it. As such, one approach would be to ignore all base-class properties and only serialize those in the defined class. (Technically this won't work because if you subclass that subclass you break the serialization, but it did make me wonder...) Is it possible via reflection (well I know the answer is 'yes' because Reflector does

Class base() constructor and pass this

不羁岁月 提交于 2019-12-19 20:43:42
问题 I am trying to implement good design patterns for a program I am writing. I have a class structure like this. abstract class SomeBase { public SomeObject obj { get; protected set; } protected SomeBase(SomeObject x) { obj = x; } //Other methods and fields... } public class SomeDerived : SomeBase { public SomeDerived() : base(new SomeObject(this)) { } } Now as I;m sure you now, you can't pass this in a contructor because the object hasn't bee initialized. But I was really hoping there was a

How do we call a virtual method from another method in the base class even when the current instance is of a derived-class?

喜夏-厌秋 提交于 2019-12-19 20:15:29
问题 How do we call a virtual method from another method in the base class even when the current instance is of a derived-class? I know we can call Method2 in the Base class from a method in the Derived class by using base.Method2() but what I want to do is calling it from the other virtual method in the Base class. Is it possible? using System; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { Base b = new Derived( ); b.Method1( ); } } public class Base { public

Can I have a base class where each derived class has its own copy of a static property?

冷暖自知 提交于 2019-12-19 07:49:48
问题 I have something like the following situation below: class Base { public static int x; public int myMethod() { x += 5; return x; } } class DerivedA : Base { } class DerivedB : Base { } I am trying to set this up so that each derived class has its own static instance of x, if I do something like this: DerivedA.x = 5; DerivedB.x = 10; then when I run: DerivedA.myMethod(); //The result will be 10 DerivedB.myMethod(); //The reusult will be 15 Can i do something like this? How can I setup the