I have a project which uses Autofac to instantiate the objects
builder.RegisterType<AbcWebWorkContext>().As<IWorkContext>().InstancePerHttpRequest();
This AbcWebWorkContext
is a subclass of WebWorkContext
:
public partial class AbcWebWorkContext : WebWorkContext
In my AbcWebWorkContext
I would like to hide a method and a property from the parent class
protected new Customer GetCurrentCustomer(){ //do stuff }
new public Customer CurrentCustomer { //do studd }
But when someone calls
_workContext.CurrentCustomer
The base class property is called. If I call it like this
((AbcWebWorkContext) _workContext).CurrentCustomer
it works.
I would like to know why I am not able to hide the parent method.
I can't change the called class because it is in NopCommerce
's core, which I would not like to change.
Why is it not hiding the method?
Base class declaration of the methods:
protected Customer GetCurrentCustomer() { // do stuff }
public Customer CurrentCustomer{ // do stuff }
calling GetType()
on _workcontext
will output
{Name = "AbcWebWorkContext" FullName = "Nop.Web.Framework.AbcWebWorkContext"}
The type hierarchy is IWorkContext
(interface) « WebWorkContext
« AbcWebWorkContext
_workContext
is declared as IWorkContext
and Autofac generates an instance as AbcWebWorkContext
(as shown above)