public static ImplicitBias BiasFromXElement(ImplicitXmlChain chain, XElement xElement) { var sourceString = (xElement.Attribute("source") != null ? xElement.Attribute("source").Value : String.Empty); var low = (xElement.Attribute("low") != null ? xElement.Attribute("low").Value : String.Empty); ImplicitBias autoCorrect; ImplicitModuleBase source; Double value; if (!String.IsNullOrEmpty(sourceString)) { if (chain.Modules.TryGetValue(sourceString, out source)) { autoCorrect = new ImplicitBias(source, 0); } else if (Double.TryParse(sourceString, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) { autoCorrect = new ImplicitBias(value, 0); } else { throw new InvalidOperationException("Invalid source value"); } } else { throw new InvalidOperationException("Missing source"); } if (!String.IsNullOrEmpty(low)) { if (chain.Modules.TryGetValue(sourceString, out source)) { autoCorrect.Bias = source; } else if (Double.TryParse(low, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) { autoCorrect.Bias = value; } else { throw new InvalidOperationException("Invalid bias value"); } } return(autoCorrect); }
public static ImplicitBias BiasFromXElement(ImplicitXmlChain chain, XElement xElement) { var sourceString = (xElement.Attribute("source") != null ? xElement.Attribute("source").Value : String.Empty); var low = (xElement.Attribute("low") != null ? xElement.Attribute("low").Value : String.Empty); ImplicitBias autoCorrect; ImplicitModuleBase source; Double value; if (!String.IsNullOrEmpty(sourceString)) { if (chain.Modules.TryGetValue(sourceString, out source)) autoCorrect = new ImplicitBias(source, 0); else if (Double.TryParse(sourceString, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) autoCorrect = new ImplicitBias(value, 0); else throw new InvalidOperationException("Invalid source value"); } else throw new InvalidOperationException("Missing source"); if (!String.IsNullOrEmpty(low)) { if (chain.Modules.TryGetValue(sourceString, out source)) autoCorrect.Bias = source; else if (Double.TryParse(low, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) autoCorrect.Bias = value; else throw new InvalidOperationException("Invalid bias value"); } return autoCorrect; }