|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Xml;
using EnvDTE80;
using Microsoft.VisualStudio.Shell.Interop;
namespace SwitchFramework
{
/// <summary>
/// Base abstract class for all switches.
/// </summary>
internal abstract class CustomSwitch
{
#region Events and Delegates
/// <summary>
/// Fires before executing switch.
/// </summary>
virtual public event EventHandler BeforeExecuting;
/// <summary>
/// Fires after executing switch.
/// </summary>
virtual public event EventHandler AfterExecuting;
#endregion
#region Constructors
/// <summary>
/// Default contructor.
/// </summary>
protected CustomSwitch()
{
}
/// <summary>
/// Contructor.
/// </summary>
/// <param name="package">Package that launch command.</param>
/// <param name="name">Custom switch name.</param>
/// <param name="parameters">Custom switch parameters.</param>
protected CustomSwitch(ISwitchPackage package, string name, string[] parameters)
{
_package = package;
_name = name;
_parameters = parameters;
}
#endregion
#region Properties
ISwitchPackage _package = null;
/// <summary>
/// Gets ISwitchPackage.
/// </summary>
protected ISwitchPackage Package
{
get { return _package; }
}
string _name = string.Empty;
/// <summary>
/// Gets switch name.
/// </summary>
public string Name
{
get { return _name; }
}
string[] _parameters = null;
/// <summary>
/// Gets switch parameters.
/// </summary>
public string[] Parameters
{
get { return _parameters; }
}
#endregion
#region Public Functions
/// <summary>
/// Checks parameters and executes the command.
/// </summary>
virtual public void Execute()
{
if (!CheckContext())
throw new SwitchException(Resources.IllegalSwitchOrOption);
if (BeforeExecuting != null)
BeforeExecuting(this, null);
Executing();
if (AfterExecuting != null)
AfterExecuting(this, null);
}
#endregion
#region Protected Functions
/// <summary>
/// Executes the command.
/// </summary>
abstract protected void Executing();
/// <summary>
/// Checks switch and options.
/// </summary>
/// <returns>Returns true if all right.</returns>
virtual protected bool CheckContext()
{
return true;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a biomedical engineer. I work in Genoa as software developer. I developed MFC ActiveX controls for industrial automation for 2 years and packages for Visual Studio 2005 for 1 year. Currently I'm working in .NET 3.5 in biomedical area.