/// <summary> /// Constructor /// </summary> /// <param name="paramType">Strongly typed enum of the new parameter</param> /// <param name="name">Parameter name</param> /// <param name="dataType">Parameter .NET data type (as a Type)</param> /// <param name="description">Parameter description</param> /// <remarks>Does not verify that paramID is a valid member of FrameParamKeyType</remarks> public FrameParamDef(FrameParamKeyType paramType, string name, Type dataType, string description = "") { ParamType = paramType; Name = name; DataType = dataType; Description = description; }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="valueIfMissing">Value to return if the parameter is not defined</param> /// <returns>Value (dynamic)</returns> public dynamic GetValue(FrameParamKeyType paramType, dynamic valueIfMissing) { if (Values.TryGetValue(paramType, out var paramEntry)) { return(paramEntry.Value); } return(valueIfMissing); }
/// <summary> /// Constructor /// </summary> /// <param name="paramType">Strongly typed enum of the new parameter</param> // ReSharper disable once UnusedMember.Global public FrameParamDef(FrameParamKeyType paramType) { var paramDef = FrameParamUtilities.GetParamDefByType(paramType); ParamType = paramDef.ParamType; Name = paramDef.Name; DataType = paramDef.DataType; Description = paramDef.Description; }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="valueIfMissing">Value to return if the parameter is not defined</param> /// <returns>Value (int)</returns> public int GetValueInt32(FrameParamKeyType paramType, int valueIfMissing) { if (Values.TryGetValue(paramType, out var paramEntry)) { if (FrameParamUtilities.ConvertDynamicToInt32(paramEntry.Value, out int result)) { return(result); } } return(valueIfMissing); }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="valueIfMissing">Value to return if the parameter is not defined</param> /// <returns>Value (double)</returns> public double GetValueDouble(FrameParamKeyType paramType, double valueIfMissing) { if (Values.TryGetValue(paramType, out var paramEntry)) { if (FrameParamUtilities.ConvertDynamicToDouble(paramEntry.Value, out double result)) { return(result); } } return(valueIfMissing); }
/// <summary> /// Add or update a parameter's value /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="value">Value (dynamic)</param> private FrameParams AddUpdateValueDynamic(FrameParamKeyType paramType, dynamic value) { if (Values.TryGetValue(paramType, out var paramEntry)) { paramEntry.Value = value; } else { paramEntry = new FrameParam(FrameParamUtilities.GetParamDefByType(paramType), value); Values.Add(paramType, paramEntry); } UpdateCachedParam(paramType, value); return(this); }
/// <summary> /// Constructor /// </summary> /// <param name="paramType">Strongly typed enum of the new parameter</param> /// <param name="name">Parameter name</param> /// <param name="dataType">Parameter .NET data type (as a string)</param> /// <param name="description">Parameter description</param> /// <remarks>Does not verify that paramID is a valid member of FrameParamKeyType</remarks> public FrameParamDef(FrameParamKeyType paramType, string name, string dataType, string description = "") { ParamType = paramType; Name = name; try { DataType = Type.GetType(dataType); if (DataType == null) { dataType = GlobalParamUtilities.GetDataTypeFromAlias(dataType); DataType = Type.GetType(dataType) ?? typeof(object); } } catch { DataType = typeof(object); } Description = description; }
private void UpdateCachedParam(FrameParamKeyType paramType, dynamic value) { if (value == null) { return; } // Update cached member variables // At present, the only cached values are mass calibration coefficients switch (paramType) { case FrameParamKeyType.MassCalibrationCoefficienta2: mCachedMassCalibrationCoefficients.a2 = (double)value; break; case FrameParamKeyType.MassCalibrationCoefficientb2: mCachedMassCalibrationCoefficients.b2 = (double)value; break; case FrameParamKeyType.MassCalibrationCoefficientc2: mCachedMassCalibrationCoefficients.c2 = (double)value; break; case FrameParamKeyType.MassCalibrationCoefficientd2: mCachedMassCalibrationCoefficients.d2 = (double)value; break; case FrameParamKeyType.MassCalibrationCoefficiente2: mCachedMassCalibrationCoefficients.e2 = (double)value; break; case FrameParamKeyType.MassCalibrationCoefficientf2: mCachedMassCalibrationCoefficients.f2 = (double)value; break; } }
/// <summary> /// Lookup whether or not a frame parameter is defined /// </summary> /// <param name="paramType">Parameter type</param> /// <returns>True if defined, otherwise false</returns> public bool HasParameter(FrameParamKeyType paramType) { return(Values.ContainsKey(paramType)); }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="valueIfMissing">Value to return if the parameter is not defined</param> /// <returns>Value (dynamic)</returns> public string GetValueString(FrameParamKeyType paramType, string valueIfMissing = "") { return(GetValue(paramType, valueIfMissing)); }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <returns>Value (int)</returns> /// <remarks>Returns 0 if not defined</remarks> public int GetValueInt32(FrameParamKeyType paramType) { return(GetValueInt32(paramType, 0)); }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <returns>Value (double)</returns> /// <remarks>Returns 0 if not defined</remarks> public double GetValueDouble(FrameParamKeyType paramType) { return(GetValueDouble(paramType, 0.0)); }
/// <summary> /// Get the value for a parameter /// </summary> /// <param name="paramType">Parameter type</param> /// <returns>Value (dynamic)</returns> public dynamic GetValue(FrameParamKeyType paramType) { var defaultValue = FrameParamUtilities.GetDefaultValueByType(paramType); return(GetValue(paramType, defaultValue)); }
/// <summary> /// Add or update a parameter's value /// </summary> /// <param name="paramType">Parameter type</param> /// <param name="value">Value (dynamic)</param> public FrameParams AddUpdateValue(FrameParamKeyType paramType, dynamic value) { return(AddUpdateValueDynamic(paramType, value)); }