This project is read-only.

Excluding base classes

May 3, 2012 at 6:50 PM

I have a BaseController.cs in my controllers folder. Is there a way I can exclude this? It causes quite a few "hides inherited member" warnings.

May 3, 2012 at 7:15 PM

Can you give a more complete description of the situation that leads to this?

May 3, 2012 at 8:38 PM

I can try :) a developer in the group has added

public class BaseController : Controller

inside of the \Controllers folder of one of our MVC applications. When the T4MVC tt is run it naturally generates "BaseController.generated.cs" along with marking the ActionResult's virtual. This creates the error I described.

My initial thought was that I could simply move the base class outside of the \Controllers folder but I figured there might be a better solution.

May 3, 2012 at 8:40 PM

Can you try making it abstract? I would think it should never be instantiated directly, and I believe that will cause T4MVC to ignore it.

May 3, 2012 at 9:03 PM

lol... I agree with you. I suggested that to him initially but he seemed miffed at my suggestion. I will try it anyway, report back asap.

May 3, 2012 at 9:36 PM

But actually, I'm not sure I understand why you get that warning. I would need a more complete repro that includes what you have in the base class and one of the derived classes. Is the derived class overriding action methods from the base?

May 4, 2012 at 4:09 PM
Edited May 4, 2012 at 4:13 PM
For the record, marking it abstract was the solution. I know that... my bad eyes didn't catch the other guys code.  Here is my example anyway.

public partial class BaseController : Controller
{
	public BaseController()
		: base()
	{
	}

	[HttpGet]
	public virtual new ActionResult Request()
	{
		//do something here
	}
}


public partial class DemoController : BaseController
{
	[HttpGet]
	public virtual ActionResult JQueryUIComponents()
	{
	     return View("~/Views/Demos/JQueryUIComponents.cshtml");
	}
}
so what happens in the generated classes is this ... the BaseController gets generated along 
with the usual methods that 
get added to the generated classes... but they also get added
to the child DemoController... I mean I'm sure you see the issue you are totally correct
and I should have seen that a mile off. It seems that a lot of "web" programmers think
they are also OOP. 
    public partial class BaseController {
        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected BaseController(Dummy d) { }

        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected RedirectToRouteResult RedirectToAction(ActionResult result) {
            var callInfo = result.GetT4MVCResult();
            return RedirectToRoute(callInfo.RouteValueDictionary);
        }

        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected RedirectToRouteResult RedirectToActionPermanent(ActionResult result) {
            var callInfo = result.GetT4MVCResult();
            return RedirectToRoutePermanent(callInfo.RouteValueDictionary);
        }
}
public partial class DemoController {
        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        public DemoController() { }

        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected DemoController(Dummy d) { }

        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected RedirectToRouteResult RedirectToAction(ActionResult result) {
            var callInfo = result.GetT4MVCResult();
            return RedirectToRoute(callInfo.RouteValueDictionary);
        }

        [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
        protected RedirectToRouteResult RedirectToActionPermanent(ActionResult result) {
            var callInfo = result.GetT4MVCResult();
            return RedirectToRoutePermanent(callInfo.RouteValueDictionary);
        }
}
May 4, 2012 at 5:34 PM

Ah yes, got it, I understand the warnings now. Anyway, glad abstract takes care of it!