You can use generics to do this:
private void CreateTaskPane<T>(string title) where T : UserControl, new()
{
T taskPaneView = new T();
taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, title);
taskPane.Visible = true;
}
You would then call it via:
CreateTaskPane<CalendarView>(newTitle);
Alternatively, you could write this as:
private void CreateTaskPane<T>(T taskPaneView, string title) where T : UserControl
{
taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, title);
taskPane.Visible = true;
}
Then call via:
CreateTaskPane(new CalendarView(), newTitle);