Compile-time Validation
This section explains how the plug-in manifest generator validates extensions at compile-time and how to provide custom validation when developing extension points.
Compile-time Validation
In order to catch as many developer errors as possible at compile-time, the plug-in framework provides a mechanism for extension point developers to validate extension definitions at compile-time.
Every ExtensionAttribute and AuxiliaryExtensionAttribute has validation methods which are called during the build process. These methods then have the ability to report errors and warnings, which will be displayed in Visual Studio as standard compiler errors.
Extension Attribute Validation
TheExtensionAttribute type has a Validate
method, which by default validates that the user has specified values for the Id
and the Name
property. When developing and extension point, this method can be overridden to perform additional validation.
In the message transmitter example, the MessageTransmitterAttribute
checks whether the IMessageTransmitter
interface is implemented and raises an error if it is not.
[ExtensionPointInfo("Message Transmitters", ExtensionPointBehavior.Static)]
public class MessageTransmitterAttribute : ExtensionAttribute
{
private double _costPerCharacter;
/// <summary>
/// Constructor for XML serialization
/// </summary>
public MessageTransmitterAttribute()
{
}
/// <summary>
/// Constructor using basic properties.
/// </summary>
public MessageTransmitterAttribute(string id, string name, string description)
: base(id, name, description)
{
}
/// <summary>
/// Gets or sets the cost in dollar per character in the message.
/// </summary>
public double CostPerCharacter
{
get { return _costPerCharacter; }
set { _costPerCharacter = value; }
}
/// <summary>
/// Validates that the extension implements the IMessageTransmitter interface.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public override void Validate(
Sdl.Core.PluginFramework.Validation.IExtensionAttributeInfo info,
Sdl.Core.PluginFramework.Validation.IExtensionValidationContext context)
{
base.Validate(info, context);
context.ValidateRequiredInterface(typeof(IMessageTransmitter));
}
}
#endregion MessageTransmitterAttribute
}
Auxiliary Extension Attribute Validation
Also the [AuxiliaryExtensionAttribute](../../api/core/Sdl.Core.PluginFramework.AuxiliaryExtensionAttribute.yml type has a Validate
method, which by default doesn't do any special validation. Extension point developers can override this method to perform additional validation for an auxiliary extension attribute.
Note
This content may be out-of-date. To check the latest information on this topic, inspect the libraries using the Visual Studio Object Browser.