public IModuleParameter Clone() { ModuleParameter copy = new ModuleParameter(); copy.Name = this.Name; if (this.Value is ICloneable) { copy.Value = (this.Value as ICloneable).Clone(); } else { string error = null; // we can't have them referencing the same object or changing one will change the original if (Value != null) { copy.Value = ArbitraryParameterParser.ArbitraryParameterParse(this.Type, this.Value.ToString(), ref error); } else { copy.Value = null; } } copy.Description = this.Description; copy.VariableName = this.VariableName; copy.OnField = this.OnField; copy.SystemParameter = this.SystemParameter; copy.QuickParameter = this.QuickParameter; copy.BelongsTo = this.BelongsTo; copy.Type = this.Type; return(copy); }
/// <summary> /// Assign the given value to all of the parameters, /// if it fails roll back to the old value /// </summary> /// <param name="value">The new value to assign to</param> /// <returns>True if all of the parameters were updated successfully</returns> private bool AssignValue(string value, ref string error) { // we can not cache the values because they are pointers, not value types // this lets us deal with cases where parameters are later removed from the // linked parameter set // assign the new value to all of the parameters for (int i = 0; i < this.Parameters.Count; i++) { this.Parameters[i].Value = ArbitraryParameterParser.ArbitraryParameterParse(this.Parameters[i].Type, value, ref error); // if it failed, roll back if (this.Parameters[i].Value == null) { error = "Failed to assign to parameter " + this.Parameters[i].Name + "\r\n" + error; for ( ; i >= 0; i--) { this.Parameters[i].Value = ArbitraryParameterParser.ArbitraryParameterParse(this.Parameters[i].Type, this.Value, ref error); } return(false); } } // if we got here then all of the parameters were assigned correctly return(true); }
/// <summary> /// Create a default value of the given type for a parameter /// </summary> /// <param name="defaultValue">The default value of this field</param> /// <param name="description">A description of what this field is supposed to be used for</param> /// <param name="type">The type to process</param> /// <param name="name">The name of the parameter</param> public ParameterAttribute(string name, string defaultValue, Type type, string description) { this.Name = name; this.Description = description; string error = null; this.DefaultValue = ArbitraryParameterParser.ArbitraryParameterParse(type, defaultValue, ref error); }
/// <summary> /// Create a default value of the given type for a parameter /// </summary> /// <param name="defaultValue">The default value of this field</param> /// <param name="description">A description of what this field is supposed to be used for</param> /// <param name="type">The type to process</param> /// <param name="name">The name of the parameter</param> public ParameterAttribute(string name, string defaultValue, Type type, int index, string description) { Name = name; Description = description; string error = null; Index = index; DefaultValue = ArbitraryParameterParser.ArbitraryParameterParse(type, defaultValue, ref error); }
/// <summary> /// Attempts to set the value of the parameter to the new given value /// </summary> /// <param name="newValue">The value to change the parameter to</param> /// <param name="error">If the value is invalid this will contain a message as to why.</param> /// <returns>True if the parameter was set to the new value, false otherwise with an error message in error.</returns> public bool SetValue(string newValue, ref string error) { ParameterChange change = new ParameterChange(); return(Session.RunCommand(XTMFCommand.CreateCommand( // do ((ref string e) => { // Check to see if we are in a linked parameter change.ContainedIn = Session.ModelSystemModel.LinkedParameters.GetContained(this); if (change.ContainedIn == null) { change.NewValue = newValue; change.OldValue = _Value; if (!ArbitraryParameterParser.Check(RealParameter.Type, change.NewValue, ref e)) { return false; } Value = change.NewValue; } else { change.NewValue = newValue; change.OldValue = change.ContainedIn.GetValue(); return change.ContainedIn.SetWithoutCommand(change.NewValue, ref e); } return true; }), // undo (ref string e) => { if (change.ContainedIn == null) { Value = change.OldValue; } else { return change.ContainedIn.SetWithoutCommand(change.OldValue, ref e); } return true; }, // redo (ref string e) => { if (change.ContainedIn == null) { Value = change.NewValue; } else { return change.ContainedIn.SetWithoutCommand(change.NewValue, ref e); } return true; } ), ref error)); }
private static void AssignTypeValue(XmlAttribute paramTIndex, XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam, Dictionary <int, Type> lookUp) { string error = null; var temp = ArbitraryParameterParser.ArbitraryParameterParse(selectedParam.Type, paramValueAttribute.InnerText, ref error); if (temp != null) { // don't overwrite the default if we are loading something bad selectedParam.Value = temp; } }
/// <summary> /// Internally set the value of the linked parameter without using a command in the session. /// </summary> /// <param name="newValue">The value to set it to</param> /// <param name="error">An error message in case of failure</param> /// <returns>True if successful, false if there is an error.</returns> internal bool SetWithoutCommand(string newValue, ref string error) { lock (ParameterModelsLock) { foreach (var parameter in ParameterModels) { if (!ArbitraryParameterParser.Check(parameter.RealParameter.Type, newValue, ref error)) { return(false); } } if (!RealLinkedParameter.SetValue(newValue, ref error)) { return(false); } foreach (var parameter in ParameterModels) { parameter.UpdateValueFromReal(); } } return(true); }
/// <summary> /// Add a new parameter to this linkedParameter set /// </summary> /// <param name="parameter">The parameter to add</param> /// <returns>If we were able to add the parameter</returns> public bool Add(IModuleParameter parameter, ref string error) { // you can't have the same parameter multiple times! if (parameter == null) { error = "The parameter does not exist!"; return(false); } if (this.Parameters.Contains(parameter)) { error = "The parameter '" + parameter.Name + "' already exists within the linked parameter '" + this.Name + "'."; return(false); } var value = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, this.Value, ref error); if (value == null) { return(false); } parameter.Value = value; this.Parameters.Add(parameter); return(true); }