//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (Density <= 0 || Density > 1) { throw new ArgumentException($"Invalid Density {Density.ToString(CultureInfo.InvariantCulture)}. Density must be GT 0 and LE to 1.", "Density"); } if (AvgDistance < 0) { throw new ArgumentException($"Invalid AvgDistance {AvgDistance.ToString(CultureInfo.InvariantCulture)}. AvgDistance must be GE to 0.", "AvgDistance"); } if (Repetitions < 1) { throw new ArgumentException($"Invalid Repetitions {Repetitions.ToString(CultureInfo.InvariantCulture)}. Repetitions must be GT 0.", "Repetitions"); } return; }
/// <summary> /// Generates xml element containing the settings. /// </summary> /// <param name="rootElemName">Name to be used as a name of the root element.</param> /// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param> /// <returns>XElement containing the settings</returns> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultDensity) { rootElem.Add(new XAttribute("density", Density.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultAvgDistance) { rootElem.Add(new XAttribute("avgDistance", IsDefaultAvgDistance ? DefaultAvgDistanceCode : AvgDistance.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultAllowSelfConnection) { rootElem.Add(new XAttribute("allowSelfConnection", AllowSelfConnection.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultConstantNumOfConnections) { rootElem.Add(new XAttribute("constantNumOfConnections", ConstantNumOfConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultReplaceExistingConnections) { rootElem.Add(new XAttribute("replaceExistingConnections", ReplaceExistingConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultRepetitions) { rootElem.Add(new XAttribute("repetitions", Repetitions.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }