Skip to content

Commit

Permalink
Do not implement props in ViewExtensionBase (DynamoDS#11350)
Browse files Browse the repository at this point in the history
This changes the definition of ViewExtensionBase to use abstract rather
than virtual for the definition of required properties like Name and
UniqueId. The use of virtual was creating a backing field which was not
used in ViewExtensionBase and could not be assigned in the inheriting
class, making it pretty much useless.

Also the Dispose method is declared as abstract, as it was already
required to implement and having a default empty implementation could
lead developers to oversight the need to dispose resources in their
extension.
  • Loading branch information
mmisol committed Dec 9, 2020
1 parent 3bf7f86 commit 9650f85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Dynamo.Controls;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Dynamo.DocumentationBrowser.Properties;
using Dynamo.Logging;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace Dynamo.DocumentationBrowser
{
Expand All @@ -24,12 +23,12 @@ public class DocumentationBrowserViewExtension : ViewExtensionBase, IViewExtensi
/// <summary>
/// Extension Name
/// </summary>
public string Name => Properties.Resources.ExtensionName;
public override string Name => Properties.Resources.ExtensionName;

/// <summary>
/// GUID of the extension
/// </summary>
public string UniqueId => "68B45FC0-0BD1-435C-BF28-B97CB03C71C8";
public override string UniqueId => "68B45FC0-0BD1-435C-BF28-B97CB03C71C8";

public DocumentationBrowserViewExtension()
{
Expand All @@ -50,12 +49,12 @@ internal void OnMessageLogged(ILogMessage msg)

#region IViewExtension lifecycle

public void Startup(ViewStartupParams viewStartupParams)
public override void Startup(ViewStartupParams viewStartupParams)
{
// Do nothing for now
}

public void Loaded(ViewLoadedParams viewLoadedParams)
public override void Loaded(ViewLoadedParams viewLoadedParams)
{
if (viewLoadedParams == null) throw new ArgumentNullException(nameof(viewLoadedParams));

Expand Down Expand Up @@ -86,11 +85,6 @@ private void MenuItemCheckHandler(object sender, RoutedEventArgs e)
AddToSidebar(true);
}

public void Shutdown()
{
// Do nothing for now
}

protected virtual void Dispose(bool disposing)
{
// Cleanup
Expand All @@ -106,7 +100,7 @@ protected virtual void Dispose(bool disposing)
/// <summary>
/// Dispose function after extension is closed
/// </summary>
public void Dispose()
public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
Expand Down
9 changes: 3 additions & 6 deletions src/DynamoCoreWpf/Extensions/ViewExtensionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ public abstract class ViewExtensionBase : IViewExtension
/// There may be multiple instances of the same type, but the application
/// will *not* allow two instances to coexist with the same id.
/// </summary>
public virtual string UniqueId { get; }
public abstract string UniqueId { get; }

/// <summary>
/// A name for the extension instance. This is used for more user-readable logging.
/// </summary>
public virtual string Name { get; }
public abstract string Name { get; }

/// <summary>
/// Dispose method for the view extension.
/// </summary>
public virtual void Dispose()
{

}
public abstract void Dispose();

/// <summary>
/// Action to be invoked when DynamoView begins to start up. This is guaranteed to happen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Windows.Controls;
using Dynamo.Controls;
using Dynamo.Extensions;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
Expand Down Expand Up @@ -32,7 +31,7 @@ internal WorkspaceDependencyView DependencyView
/// <summary>
/// Extension Name
/// </summary>
public string Name
public override string Name
{
get
{
Expand All @@ -43,7 +42,7 @@ public string Name
/// <summary>
/// GUID of the extension
/// </summary>
public string UniqueId
public override string UniqueId
{
get
{
Expand All @@ -54,7 +53,7 @@ public string UniqueId
/// <summary>
/// Dispose function after extension is closed
/// </summary>
public void Dispose()
public override void Dispose()
{
DependencyView.Dispose();
}
Expand All @@ -65,12 +64,7 @@ public void Ready(ReadyParams readyParams)
{
}

public void Shutdown()
{
// Do nothing for now
}

public void Startup(ViewStartupParams viewStartupParams)
public override void Startup(ViewStartupParams viewStartupParams)
{
pmExtension = viewStartupParams.ExtensionManager.Extensions.OfType<PackageManagerExtension>().FirstOrDefault();
}
Expand All @@ -82,7 +76,7 @@ internal void OnMessageLogged(ILogMessage msg)
this.MessageLogged?.Invoke(msg);
}

public void Loaded(ViewLoadedParams viewLoadedParams)
public override void Loaded(ViewLoadedParams viewLoadedParams)
{
DependencyView = new WorkspaceDependencyView(this, viewLoadedParams);
// when a package is loaded update the DependencyView
Expand Down

0 comments on commit 9650f85

Please sign in to comment.