When exposing a set of related functions in Powershell cmdlets, is it possible to share the property names and summary help to normalize these across cmdlets in an assembly?
I know that this can be done with derived classes, but this solution is awkward at best when there are multiple cmdlets with different properties to be shared.
Here is an extremely simple example. I would like to share the property 'Name' and all related comments so that they are the same across the N cmdlets we are producing, but I cannot think of a good way to do this in c#. Ideally any sharing would allow specification of Parameter attributes such as Mandatory or Position.
namespace FrozCmdlets
{
using System.Management.Automation;
/// <summary>
/// Adds a new froz to the system.
/// </summary>
[Cmdlet( VerbsCommon.Add, "Froz" )]
public class AddFroz : Cmdlet
{
/// <summary>
/// The name of the froz.
/// For more information on the froz, see froz help manual.
/// </summary>
[Parameter]
public string Name { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
// Add the froz here
}
}
/// <summary>
/// Removes a froz from the system.
/// </summary>
[Cmdlet( VerbsCommon.Remove, "Froz" )]
public class RemoveFroz : Cmdlet
{
/// <summary>
/// The name of the froz.
/// For more information on the froz, see froz help manual.
/// </summary>
[Parameter]
public string Name { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
// Remove the froz here
}
}
}