I have event declared in abstract class:
public abstract class AbstractClass
{
public event Action ActionEvent;
}
public class MyClass : AbstractClass
{
private void SomeMethod()
{
//Want to access ActionEvent-- Not able to do so
if (ActionEvent != null)
{
}
}
}
I wanted to access this base class event in derived. Further I wanted to access this event in some other derived class of MyClass:
MyClass.ActionEvent += DerivedMethod()
Please help me understand how to work with event defined in abstract classes.
An often used pattern for this is something like the below (you'll see a lot of it in the classes in the System.Windows.Forms namespace).
public abstract class MyClass
{
public event EventHandler MyEvent;
protected virtual void OnMyEvent(EventArgs e)
{
if (this.MyEvent != null)
{
this.MyEvent(this, e);
}
}
}
You would then use it in a derived class like this, optionally extending the behaviour:
public sealed class MyOtherClass : MyClass
{
public int MyState { get; private set; }
public void DoMyEvent(bool doSomething)
{
// Custom logic that does whatever you need to do
if (doSomething)
{
OnMyEvent(EventArgs.Empty);
}
}
protected override void OnMyEvent(EventArgs e)
{
// Do some custom logic, then call the base method
this.MyState++;
base.OnMyEvent(e);
}
}
This approach could be dangerous, see below for a better one
Events can only be raised (or checked for null apparently) from within the declaring class. This protection extends to derived classes.
Thus, the solution is to re-declare the event as an implementation of an abstract event in the base class. Then you can still use it via a base class reference as you want, and raise/use it in the derived class:
public abstract class AbstractClass
{
public abstract event Action ActionEvent;
}
public class MyClass : AbstractClass
{
public override event Action ActionEvent;
private void SomeMethod()
{
//Want to access ActionEvent-- Now you can!
if (ActionEvent != null)
{
}
}
}
Correct approach
MSDN Suggests that this approach may not be handled by the compiler correctly. Instead you should provide protected methods so derived classes can check for null, invoke the event, etc:
public abstract class AbstractClass
{
public event Action ActionEvent;
protected bool EventIsNull()
{
return ActionEvent == null;
}
}
public class MyClass : AbstractClass
{
private void SomeMethod()
{
//Want to access ActionEvent-- Now you can!
if (!EventIsNull())
{}
}
}
Related
Good day,
I have a base class with a virtual method that needs to be overridden per implementation, but I would like to call the base method first before overriding.
Is there a way to accomplish this without having to actually call the method.
public class Base
{
public virtual void Method()
{
//doing some stuff here
}
}
public class Parent : Base
{
public override void Method()
{
base.Method() //need to be called ALWAYS
//then I do my thing
}
}
I cannot always rely that the base.Method() will be called in the override, so I would like to enforce it somehow. This might be a design pattern of some kind, any approach to accomplish the result will do.
One way is to define a public method in the base class, which calls another method that can be (or must be) overridden:
public class Base
{
public void Method()
{
// Do some preparatory stuff here, then call a method that might be overridden
MethodImpl()
}
protected virtual void MethodImpl() // Not accessible apart from child classes
{
}
}
public class Parent : Base
{
protected override void MethodImpl()
{
// ToDo - implement to taste
}
}
You can use the decorator design pattern, applying this pattern you can attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality:
public abstract class Component
{
public abstract void Operation();
}
public class ConcreteComponent1 : Component
{
public override void Operation()
{
//logic
}
}
public abstract class ComponentDecorator : Component
{
protected readonly Component Component;
protected ComponentDecorator(Component component)
{
Component = component;
}
public override void Operation()
{
if(Component != null)
Component.Operation();
}
}
public class ConcreteDecorator : ComponentDecorator
{
public ConcreteDecorator(Component component) : base(component)
{
}
public override void Operation()
{
base.Operation();
Console.WriteLine("Extend functionality");
}
}
Hope this helps!
Say I have a base class like this:
public abstract class MyBaseClass
{
protected void MyMethod(string myVariable)
{
//...
}
}
Then I inherit this class in a separate assembly:
public abstract class MyDerivedClass : MyBaseClass
{
static readonly string MyConstantString = "Hello";
protected void MyMethod()
{
MyMethod(MyConstantString);
}
}
I now want to make sure that any other class that inherits from MyDerivedClass does not have access to the MyBaseClass.MyMethod() method. (To clarify, I still want to be able to call MyDerivedClass.MyMethod() with no parameters)
I tried using protected internal but that didn't work.
Update: I'm trying to do this because the application I'm working on has a bunch of separate programs that use a base class. There are 5 different "types" of programs, each performs a specific, separate function but they all have some common code that I am trying to abstract into this base class. The common code is 99% the same, differing only slightly depending on what type of program is calling it. This is why I have my base class taking a string parameter in the example which then disappears in the derived base class, as that class knows it performs role x so it tells its base class accordingly.
Then I would instead of inheritance use composition in the MyDerivedClass. So all derived classes from this class does not know the methods from MyBaseClass. The class MyBaseClass would i make package visible so it is not possible to use it.
abstract class MyBaseClass
{
void MyMethod(string myVariable)
{
//...
}
}
abstract class MyDerivedClass
{
static readonly string MyConstantString = "Hello";
private MyBaseClass baseClass;
MyDerivedClass(MyBaseClass baseClass)
{
this.baseClass = baseClass;
}
protected void MyMethod()
{
baseClass.MyMethod(MyConstantString);
}
}
The class names should be changed of course.
This is not quite possible. And it may be a sign that your object design might be in trouble, but that's not a question for SO.
You can try a bit more underhanded approach, though:
public abstract class MyBaseClass
{
protected abstract string MyConstantString { get; }
protected void MyMethod()
{
//...
}
}
public abstract class MyDerivedClass : MyBaseClass
{
protected override sealed string MyConstantString => "Hello";
}
Or, more typically, just use the constructor to pass the required argument:
public abstract class MyBaseClass
{
private readonly string myString;
protected MyBaseClass(string myString)
{
this.myString = myString;
}
protected void MyMethod()
{
//...
}
}
public abstract class MyDerivedClass : MyBaseClass
{
protected MyBaseClass() : base("Hello") {}
}
Classes derived from MyDerivedClass have no way to change the argument in either case, the second approach is a bit nicer from inheritance perspective (basically, the type is a closure over an argument of its ancestor type).
You cannot stop inheriting classes from calling this method - you have made it protected so your intent is for it to be accessible to classes that inherit from it, whether directly, or via another sub-class.
If you want to keep the inheritance, the best you can do is to throw an error if the sub-class calls it in MyDerivedClass:
public abstract class MyBaseClass
{
protected void MyMethod(string myVariable)
{
Console.WriteLine(myVariable);
}
}
public abstract class MyDerivedClass : MyBaseClass
{
static readonly string MyConstantString = "Hello";
protected void MyMethod()
{
base.MyMethod(MyConstantString);
}
protected new void MyMethod(string myVariable)
{
throw new Exception("Not allowed");
}
}
public class SubDerivedClass : MyDerivedClass
{
static readonly string MyConstantString = "Hello";
public void Foo()
{
MyMethod(MyConstantString);
}
}
When Foo() is called in SubDerivedClass, it will call MyMethod in DerivedClass, which will throw the Exception.
I'm trying to create an event delegate where the parameter is strongly typed to match the current class, like this:
public class HPCRequest
{
public delegate void RequestCompleteHandler(HPCRequest request);
public event RequestCompleteHandler RequestComplete;
The problem is that the point of this class is to be inherited, and what I really want is for all those inheriting classes to have the "RequestComplete" event, where the delegate is typed for that class:
public class HPCGetConfig : HPCRequest
{
//I want this class to effectively inherit something like this:
//public delegate void RequestCompleteHandler(HPCGetConfig request);
This is because currently, when I have a function that handles one of my "RequestComplete" events, I currently have to do this:
myGetConfigRequest.RequestComplete += new HPCRequest.RequestCompleteHandler(HPCGetExpectedLosses_RequestComplete);
void HPCGetConfig_RequestComplete(HPCRequest request)
{
HPCGetConfig thisRequest = request as HPCGetConfig;
//This should be strongly typed in the first place.
But I want to be able to do something like this:
request.RequestComplete += new HPCGetConfig.RequestCompleteHandler(HPCGetConfig_RequestComplete);
request.SendRequestAsync();
}
void HPCGetConfig_RequestComplete(HPCGetConfig request)
{
request.RequestComplete -= HPCGetConfig_RequestComplete;
Attempts
I've tried this:
public delegate void RequestCompleteHandler<T>(T request) where T : HPCRequest;
public event RequestCompleteHandler<T> RequestComplete;
but when I try to invoke the event from within the base class using RequestComplete(this);, I get a compile time error: `Delegate 'RequestCompleteHandler' has some invalid arguments.
This happens whether or not I set up the entire HPCRequest class as HPCRequest<T> by going:
public class HPCRequest<T> where T : HPCRequest<T>
{
public delegate void RequestCompleteHandler<T>(T request);
public event RequestCompleteHandler<T> RequestComplete;
public class HPCGetConfig : HPCRequest<HPCGetConfig> { ...
The same error occurs when I try to invoke the event: RequestComplete(this);
I've also tried all forms of creating the delegate and event and overriding them, such as in doing:
public class HPCRequest
{
public delegate void RequestCompleteHandler(HPCRequest request);
public virtual event RequestCompleteHandler RequestComplete;
public sealed class HPCGetConfig : HPCRequest
{
public delegate void RequestCompleteHandler(HPCGetConfig request);
public override event RequestCompleteHandler RequestComplete;
But this gives me a compile time error because I cannot override the RequestComplete event with one of a different delegate type.
Any other ideas?
Edit
Templating the entire HPCRequest class is not an option, after a very thorough attempt, I see that it just screws up every attempt to use the type HPCRequest as a placeholder for any request type. If this solution is going to work, the class HPCRequest must be able to be instantiated and inherited from without specifying a type parameter. I'll need a solution that doesn't require templating HPCRequest.
To make sure everyone know exactly how I'm trying to use this, I pasted some sample code into pastebin that should let you experiment with ways of getting this event templating working without breaking anything. Here it is: http://pastebin.com/bbEYgLj1
What you could try:
public abstract class HPCRequest<T> where T : HPCRequest<T>
{
public delegate void RequestCompleteHandler(T request);
public event RequestCompleteHandler RequestComplete;
protected void RaiseRequestComplete(T request)
{
if (RequestComplete != null)
{
RequestComplete(request);
}
}
}
public class Foo : HPCRequest<Foo>
{
public void Bar()
{
RaiseRequestComplete(this);
}
}
public class Example
{
public static void Test()
{
var request = new Foo();
request.RequestComplete += RequestComplete;
}
static void RequestComplete(Foo request)
{
// It's a Foo!
}
}
This self-referential generic constraint allows what you want I think. I added the protected RaiseRequestCompleted so you can still raise the event from classes that inherit from HCPRequest. Otherwise, only HCPRequest would be allowed to do so.
UPDATE: I updated the code to pass this and added sample code that matches your desired result.
You can use generic type parameter for this purposes so each class inherited from HPCRequest must specify a generic type parameter. Also I would suggest marking classes which are designed to be a base class by abstract modifier to avoid explicit instantiation:
public abstract class HPCRequest<TRequest>
where TRequest: class
{
public delegate void RequestCompleteHandler(TRequest request);
public event RequestCompleteHandler<TRequest> RequestComplete;
}
public sealed class HPCGetConfig : HPCRequest<HPCGetConfig>
{
}
You can constrain the type parameter of the abstract class to be derived from the abstract class itself. It seems strange, but you can set it up like this:
public abstract class HPCRequest<T> where T : HPCRequest<T>
{
public delegate void RequestCompleteHandler(T request);
public event RequestCompleteHandler RequestComplete;
}
public class DerivedHPCRequest : HPCRequest<DerivedHPCRequest>
{
}
Your use case is a great candidate for explicitly implementing a non-generic interface in a generic base class. I'm not certain that I am completely understanding the desired functionality, but I think I did. I wrote some code (below) that should get you started.
As a side note, there isn't a real reason to declare the delegates. For consistency with MSDN Event Design standards, your solution would use EventHandler<T> and a custom EventArgs implementation.
Code
// this is a sample program using the pattern i am recommending
// I'm pretty sure this is what you wanted your code to look like?
public class Program
{
public static void Main()
{
var request = new HPCGetConfig();
request.RequestComplete += HandleConfigRequestCompleted;
request.SendAsync();
}
static void HandleConfigRequestCompleted(object sender, RequestCompleteEventArgs<HPCGetConfig> e)
{
var request = e.Request;
// do something with the request
}
}
// the non-generic event args class
public abstract class RequestCompleteEventArgs : EventArgs
{
public abstract Type RequestType { get; }
public abstract object RequestObject { get; set; }
}
// the generic event args class
public class RequestCompleteEventArgs<T> : RequestCompleteEventArgs
{
private T m_Request;
public T Request
{
get { return m_Request; }
set { m_Request = value; }
}
public override Type RequestType
{
get { return typeof(T); }
}
public override object RequestObject
{
get { return Request; }
set
{
if (!(value is T))
{
throw new ArgumentException("Invalid type.", "value");
}
m_Request = (T)value;
}
}
}
// the non-generic interface
public interface IHPCRequest
{
event EventHandler<RequestCompleteEventArgs> RequestComplete;
}
// the generic base class
public abstract class HPCRequest<T> : IHPCRequest
where T : HPCRequest<T>
{
// this sanitizes the event handler, and makes it callable
// whenever an event handler is subscribed to the non-generic
// interface
private static EventHandler<RequestCompleteEventArgs<T>> ConvertNonGenericHandler(EventHandler<RequestCompleteEventArgs> handler)
{
return (sender, e) => handler(sender, e);
}
// this object is for a lock object for thread safety on the callback event
private readonly object Bolt = new object();
// This determines whether the send method should raise the completed event.
// It is false by default, because otherwise you would have issues sending the request asynchronously
// without using the SendAsync method.
public bool AutoRaiseCompletedEvent { get; set; }
// This is used to ensure that RequestComplete event cannot fire more than once
public bool HasRequestCompleteFired { get; private set; }
// declare the generic event
public event EventHandler<RequestCompleteEventArgs<T>> RequestComplete;
// explicitly implement the non-generic interface by wiring the the non-generic
// event handler to the generic event handler
event EventHandler<RequestCompleteEventArgs> IHPCRequest.RequestComplete
{
add { RequestComplete += ConvertNonGenericHandler(value); }
remove { RequestComplete -= ConvertNonGenericHandler(value); }
}
// I'm not 100% clear on your intended functionality, but this will call an overrideable send method
// then raise the OnRequestCompleted event if the AutoRaiseCompletedEvent property is set to 'true'
public void Send()
{
SendRequest((T)this);
if(AutoRaiseCompletedEvent)
{
OnRequestCompleted((T)this);
}
}
public void SendAsync()
{
// this will make the event fire immediately after the SendRequest method is called
AutoRaiseCompletedEvent = true;
new Task(Send).Start();
}
// you can make this virtual instead of abstract if you don't want to require that the Request
// class has the Send implementation
protected abstract void SendRequest(T request);
// this raises the RequestCompleted event if it is the first call to this method.
// Otherwise, an InvalidOperationException is thrown, because a Request can only
// be completed once
public void OnRequestCompleted(T request)
{
bool invalidCall = false;
Exception handlerException = null;
if (HasRequestCompleteFired)
invalidCall = true;
else
{
lock(Bolt)
{
if(HasRequestCompleteFired)
{
invalidCall = true;
}
else
{
if (RequestComplete != null)
{
// because you don't want to risk throwing an exception
// in a locked context
try
{
RequestComplete(this, new RequestCompleteEventArgs<T> { Request = request });
}
catch(Exception e)
{
handlerException = e;
}
}
HasRequestCompleteFired = true;
}
}
}
if(invalidCall)
{
throw new InvalidOperationException("RequestCompleted can only fire once per request");
}
if(handlerException != null)
{
throw new InvalidOperationException("The RequestComplete handler threw an exception.");
}
}
}
// a sample concrete implementation
public class HPCGetConfig : HPCRequest<HPCGetConfig>
{
protected override void SendRequest(HPCGetConfig request)
{
// do some configuration stuff
}
}
I think that you would have to create an abstract base class that can of cause not be instantiated:
public abstract class HPCRequestBase<T> where T : HPCRequestBase<T>
{
public delegate void RequestCompleteHandler(T request);
public event RequestCompleteHandler RequestComplete;
protected void OnRequestComplete(T request)
{
if (RequestComplete != null) {
RequestComplete(request);
}
}
public void Test( )
{
OnRequestComplete((T)this);
}
}
public class HPCRequest : HPCRequestBase<HPCRequest>
{
public void Test2()
{
OnRequestComplete(this);
}
}
public class HPCRequestConfig : HPCRequestBase<HPCRequestConfig>
{
// Derived from the base class, not from HPCRequest
}
Also 'this' has to be casted to T: OnRequestComplete((T)this);
This test runs without an error:
var hpcr = new HPCRequest();
hpcr.Test();
hpcr.Test2();
It's can't be done.
I've ended up having to cast the delegate everywhere it's used.
Happy to change the accepted answer if anything ever shows otherwise.
This question seems weird, but i came across this question in one of the interviews recently.
I ve been asked, is there a way in c# to hide the methods partially in a inherited child classes?. Assume the base class A, exposed 4 methods. Class B implements A and it will only have the access to first 2 methods and Class C implements A will only have the access to last 2 methods.
I know we can do this way
public interface IFirstOne
{
void method1();
void method2();
}
public interface ISecondOne
{
void method3();
void method4();
}
class baseClass : IFirstOne, ISecondOne
{
#region IFirstOne Members
public void method1()
{
throw new NotImplementedException();
}
public void method2()
{
throw new NotImplementedException();
}
#endregion
#region ISecondOne Members
public void method3()
{
throw new NotImplementedException();
}
public void method4()
{
throw new NotImplementedException();
}
#endregion
}
class firstChild<T> where T : IFirstOne, new()
{
public void DoTest()
{
T objt = new T();
objt.method1();
objt.method2();
}
}
class secondChild<T> where T : ISecondOne, new()
{
public void DoTest()
{
T objt = new T();
objt.method3();
objt.method4();
}
}
But what they wanted is different. They wanted to hide these classes on inheriting from baseclasses. something like this
class baseClass : IFirstOne, ISecondOne
{
#region IFirstOne Members
baseClass()
{
}
public void method1()
{
throw new NotImplementedException();
}
public void method2()
{
throw new NotImplementedException();
}
#endregion
#region ISecondOne Members
public void method3()
{
throw new NotImplementedException();
}
public void method4()
{
throw new NotImplementedException();
}
#endregion
}
class firstChild : baseClass.IFirstOne //I know this syntax is weird, but something similar in the functionality
{
public void DoTest()
{
method1();
method2();
}
}
class secondChild : baseClass.ISecondOne
{
public void DoTest()
{
method3();
method4();
}
}
is there a way in c# we can achieve something like this...
I did it by having 1 main base class and 2 sub bases.
// Start with Base class of all methods
public class MyBase
{
protected void Method1()
{
}
protected void Method2()
{
}
protected void Method3()
{
}
protected void Method4()
{
}
}
// Create a A base class only exposing the methods that are allowed to the A class
public class MyBaseA : MyBase
{
public new void Method1()
{
base.Method1();
}
public new void Method2()
{
base.Method2();
}
}
// Create a A base class only exposing the methods that are allowed to the B class
public class MyBaseB : MyBase
{
public new void Method3()
{
base.Method3();
}
public new void Method4()
{
base.Method4();
}
}
// Create classes A and B
public class A : MyBaseA {}
public class B : MyBaseB {}
public class MyClass
{
void Test()
{
A a = new A();
// No access to Method 3 or 4
a.Method1();
a.Method2();
B b = new B();
// No Access to 1 or 2
b.Method3();
b.Method4();
}
}
Although you can't do exactly what you want, you could use explicit interface implementation to help, in which the interface members are only exposed if it is explicitly cast to that interface...
Perhaps the interviewer may have been referring to method hiding?
This is where you declare a method with the same signature as on in your base class - but you do not use the override keyword (either because you don't or you can't - as when the method in the base class is non-virtual).
Method hiding, as opposed to overriding, allows you to define a completely different method - one that is only callable through a reference to the derived class. If called through a reference to the base class you will call the original method on the base class.
Don't use inheritance. It makes the public or protected facilities of the base class available directly in the derived class, so it simply isn't want you want.
Instead, make the derived class implement the relevant interface, and (if necessary) forward the methods on to a private instance of the underlying class. That is, use composition (or "aggregation") instead of inheritance to extend the original class.
class firstChild : IFirstOne
{
private baseClass _owned = new baseClass();
public void method1() { _owned.method1(); }
// etc.
}
By the way, class names should start with an upper case letter.
There is 2 solutions to hide methods inherited from a base class:
As mentioned by thecoop, you can explicitely implement the interface declaring the methods you want to hide.
Or you can simply create these methods in the base class (not inherited from any interface) and mark them as private.
Regards.
What about injecting base class as an IFirst?
interface IFirst {
void method1();
void method2();
}
interface ISecond {
void method3();
void method4();
}
abstract class Base : IFirst, ISecond {
public abstract void method1();
public abstract void method2();
public abstract void method3();
public abstract void method4();
}
class FirstChild : IFirst {
private readonly IFirst _first;
public FirstChild(IFirst first) {
_first = first;
}
public void method1() { _first.method1(); }
public void method2() { _first.method2(); }
}
Injection keeps you from violating the Interface Segregation Principle. Pure inheritance means that your FirstChild is depending on an interface that it doesn't use. If you want to retain only the IFirst functionality in Base, but ignore the rest of it, then you cannot purely inherit from Base.
I have this situation that when AbstractMethod method is invoked from ImplementClass I want to enforce that MustBeCalled method in the AbstractClass is invoked. I’ve never come across this situation before. Thank you!
public abstract class AbstractClass
{
public abstract void AbstractMethod();
public void MustBeCalled()
{
//this must be called when AbstractMethod is invoked
}
}
public class ImplementClass : AbstractClass
{
public override void AbstractMethod()
{
//when called, base.MustBeCalled() must be called.
//how can i enforce this?
}
}
An option would be to have the Abstract class do the calling in this manner. Otherwise, there is no way in c# to require an inherited class to implement a method in a certain way.
public abstract class AbstractClass
{
public void PerformThisFunction()
{
MustBeCalled();
AbstractMethod();
}
public void MustBeCalled()
{
//this must be called when AbstractMethod is invoked
}
//could also be public if desired
protected abstract void AbstractMethod();
}
public class ImplementClass : AbstractClass
{
protected override void AbstractMethod()
{
//when called, base.MustBeCalled() must be called.
//how can i enforce this?
}
}
Doing this creates the desired public facing method in the abstract class, giving the abstract class over how and in what order things are called, while still allowing the concrete class to provide needed functionality.
How about
public abstract class AbstractClass
{
public void AbstractMethod()
{
MustBeCalled();
InternalAbstractMethod();
}
protected abstract void InternalAbstractMethod();
public void MustBeCalled()
{
//this must be called when AbstractMethod is invoked
}
}
public class ImplementClass : AbstractClass
{
protected override void InternalAbstractMethod()
{
//when called, base.MustBeCalled() must be called.
//how can i enforce this?
}
}
Why can't you just call the method in the AbstractMethod() of Implement class?
One thing the preceding solutions ignore is that ImplementClass can redefine MethodToBeCalled and not call MustBeCalled -
public abstract class AbstractClass
{
public abstract void AbstractMethod();
private void MustBeCalled()
{
//will be invoked by MethodToBeCalled();
Console.WriteLine("AbstractClass.MustBeCalled");
}
public void MethodToBeCalled()
{
MustBeCalled();
AbstractMethod();
}
}
public class ImplementClass : AbstractClass
{
public override void AbstractMethod()
{
Console.WriteLine("ImplementClass.InternalAbstractMethod");
}
public new void MethodToBeCalled() {
AbstractMethod();
}
}
If only C# allowed non-overridden methods to be sealed - like Java's final keyword!
The only way I can think of to overcome this is to use delegation rather than inheritance, because classes can be defined as sealed. And I'm using a namespace and the "internal" access modifier to prevent providing a new implementation on implementing classes. Also, the method to override must be defined as protected, otherwise users could call it directly.
namespace Something
{
public sealed class OuterClass
{
private AbstractInnerClass inner;
public OuterClass(AbstractInnerClass inner)
{
this.inner = inner;
}
public void MethodToBeCalled()
{
MustBeCalled();
inner.CalledByOuter();
}
public void MustBeCalled()
{
//this must be called when AbstractMethod is invoked
System.Console.WriteLine("OuterClass.MustBeCalled");
}
}
public abstract class AbstractInnerClass
{
internal void CalledByOuter()
{
AbstractMethod();
}
protected abstract void AbstractMethod();
}
}
public class ImplementInnerClass : Something.AbstractInnerClass
{
protected override void AbstractMethod()
{
//when called, base.MustBeCalled() must be called.
//how can i enforce this?
System.Console.WriteLine("ImplementInnerClass.AbstractMethod");
}
public new void CalledByOuter()
{
System.Console.WriteLine("doesn't work");
}
}