/// <summary>Appends a field to an existing Formular, with extensive type checking.</summary> /// <param name="field">The field to be added</param> /// <param name="isRequired">A bool indicating if the registry should skip informing interested parties about this change.</param> /// <exception cref="DuplicateFieldException">This exception is thrown if a syntax error prevents the config to be parsed.</exception> /// <returns>success</returns> public bool Append(FormularFieldDescriptor field, bool isRequired) { if (!fields.ContainsKey(field.Name)) { fields[field.Name] = field; field.IsRequired = isRequired; return(true); } else { if (!fields[field.Name].Equals(field)) { throw new DuplicateFieldException("Cannot add new Field \"" + field.ToString() + "\" to Formular [" + this.Name + "]. Field is already defined as \"" + fields[field.Name].ToString() + "\".", field, fields[field.Name]); } fields[field.Name].IsRequired |= isRequired; return(true); } }
/// <summary>Constructor, that uses a given message</summary> /// <param name="formularName">The name of the new Formular.</param> /// <param name="config">Comma separated Configuration string defining the Formular</param> public MessageFormular(string formularName, string config) : this() { if (string.IsNullOrWhiteSpace(formularName)) { formularName = DYNAMIC; } this.Name = formularName.Trim(); if (string.IsNullOrWhiteSpace(config)) { return; // nothing to do here. hand back empty Formular } string[] configArray = config.Trim().Split(','); foreach (string binConfig in configArray) { var field = new FormularFieldDescriptor(binConfig, true); fields[field.Name] = field; } }
/// <summary>Checks if a field can be appended to an existing Formular, with extensive type checking.</summary> /// <param name="field">The field to be added</param> /// <returns>true, if possible to append</returns> public bool CanAppend(FormularFieldDescriptor field) { return(!fields.ContainsKey(field.Name) || fields[field.Name].Equals(field)); }
public DuplicateFieldException(string text, FormularFieldDescriptor fresh, FormularFieldDescriptor old) : base(text) { this.Fresh = fresh; this.Old = old; }