as you see, the AvoidNIL code is the same for each type, only the type of the pins is different. the code in Evaluate is not type specific, it just handles the pin data. this is a very nice example for generics. you would create one ‘template’ class with a type parameter which does the data handling and then create the nodes for each type with just 3 lines:
code(csharp):
public class AvoidNILPlugin : IPluginEvaluate
{
#region fields & pins
[Input("Input")](Input("Input"))
ISpread<T> FInput;
[Input("Default")](Input("Default"))
ISpread<T> FInput2;
[Output("Output")](Output("Output"))
ISpread<T> FOutput;
#endregion fields & pins
//called when data for any output pin is requested
public void Evaluate(int SpreadMax)
{
if (FInput.SliceCount > 0)
{
FOutput.SliceCount = FInput.SliceCount;
for (int i = 0; i < FInput.SliceCount; i++)
FOutput[i](i) = FInput[i](i);
}
else
{
FOutput.SliceCount = FInput2.SliceCount;
for (int i = 0; i < FInput2.SliceCount; i++)
FOutput[i](i) = FInput2[i](i);
}
}
}
#region PluginInfo
[PluginInfo(Name = “AvoidNILPlugin”, Category = “Value”, Help = “Replaces an empty value spread with a default value”, Tags = “empty”, Author = “aivenhoe”)](PluginInfo(Name = “AvoidNILPlugin”, Category = “Value”, Help = “Replaces an empty value spread with a default value”, Tags = “empty”, Author = “aivenhoe”))
#endregion PluginInfo
public class AvoidNILValue: AvoidNILPlugin
{
}
#region PluginInfo
[PluginInfo(Name = “AvoidNILPlugin”, Category = “Color”, Help = “Replaces an empty color spread with a default color”, Tags = “empty”, Author = “aivenhoe”)](PluginInfo(Name = “AvoidNILPlugin”, Category = “Color”, Help = “Replaces an empty color spread with a default color”, Tags = “empty”, Author = “aivenhoe”))
#endregion PluginInfo
public class AvoidNILColor: AvoidNILPlugin
{
}
#region PluginInfo
[PluginInfo(Name = “AvoidNILPlugin”, Category = “String”, Help = “Replaces an empty string spread with a default string”, Tags = “empty”, Author = “aivenhoe”)](PluginInfo(Name = “AvoidNILPlugin”, Category = “String”, Help = “Replaces an empty string spread with a default string”, Tags = “empty”, Author = “aivenhoe”))
#endregion PluginInfo
public class AvoidNILString: AvoidNILPlugin
{
}
#region PluginInfo
[PluginInfo(Name = “AvoidNILPlugin”, Category = “Transform”, Help = “Replaces an empty transformation spread with a default transformation”, Tags = “empty”, Author = “aivenhoe”)](PluginInfo(Name = “AvoidNILPlugin”, Category = “Transform”, Help = “Replaces an empty transformation spread with a default transformation”, Tags = “empty”, Author = “aivenhoe”))
#endregion PluginInfo
public class AvoidNILTransform: AvoidNILPlugin
{
}
//… and so on