Backward compatibility support for SOLIDWORKS macro feature parameters
Parameters
Macro feature parameters might need to change from version to version. And xCAD framework provides a mechanism to handle the backward compatibility of existing features.
Mark current version of parameters with ParametersVersionAttribute and increase the version if any of the parameters changed.
Implement the ParametersVersionConverter to convert from the latest version of the parameters to the newest one. Framework will take care of aligning versions in case parameters are older than one version.
Old version of parameters
[ParametersVersion("1.0", typeof(MacroFeatureParamsVersionConverter))] public class MacroFeatureParams { public string Param1 { get; set; } public int Param2 { get; set; } }
New version of parameters
[ParametersVersion("2.0", typeof(MacroFeatureParamsVersionConverter))] public class MacroFeatureParams { public string Param1A { get; set; }//parameter renamed public int Param2 { get; set; } public string Param3 { get; set; }//new parameter added }
Converter between version 1 and 2 can be implemented in the following way:
public class MacroFeatureParamsVersionConverter : ParametersVersionConverter { private class VersConv_1_0To2_0 : IParameterConverter { public void Convert(IXDocument model, IXCustomFeature feat, ref Dictionary<string, object> parameters, ref CustomFeatureSelectionInfo[] selection, ref IXDimension[] dispDims, ref IXBody[] editBodies) { var paramVal = parameters["Param1"]; parameters.Remove("Param1"); parameters.Add("Param1A", paramVal);//renaming parameter parameters.Add("Param3", "Default");//adding new parameter with default value } } public MacroFeatureParamsVersionConverter() { //conversion from version 1.0 to 2.0 Add(new Version("2.0"), new VersConv_1_0To2_0()); //add more version converters } }