// Add some non-zero constants to the mix. public void AddConstantsToTDB(RandoopConfiguration config) { foreach (SimpleTypeValues vs in config.simpleTypeValues) { Type type = Type.GetType(vs.simpleType); if (type == null) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } foreach (FileName fn in vs.fileNames) { string fileName = fn.fileName; if (!File.Exists(fileName)) { throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName); } if (type.Equals(typeof(sbyte))) { SByteReader r = new SByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(sbyte), o)); } else if (type.Equals(typeof(byte))) { ByteReader r = new ByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(byte), o)); } else if (type.Equals(typeof(short))) { ShortReader r = new ShortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(short), o)); } else if (type.Equals(typeof(ushort))) { UshortReader r = new UshortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ushort), o)); } else if (type.Equals(typeof(int))) { IntReader r = new IntReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(int), o)); } else if (type.Equals(typeof(uint))) { UintReader r = new UintReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(uint), o)); } else if (type.Equals(typeof(long))) { LongReader r = new LongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(long), o)); } else if (type.Equals(typeof(ulong))) { UlongReader r = new UlongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ulong), o)); } else if (type.Equals(typeof(char))) { CharReader r = new CharReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(char), o)); } else if (type.Equals(typeof(float))) { FloatReader r = new FloatReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(float), o)); } else if (type.Equals(typeof(double))) { DoubleReader r = new DoubleReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(double), o)); } else if (type.Equals(typeof(bool))) { BoolReader r = new BoolReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(bool), o)); } else if (type.Equals(typeof(decimal))) { DecimalReader r = new DecimalReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(decimal), o)); } else { if (!type.Equals(typeof(string))) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } Common.StringReader r = new Common.StringReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(string), o)); } } } }
/// <inheritdoc /> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!this.initialized) { Initialize(); } var message = this.errorText.ToString(); if (!(targetType == typeof(SolidAngle) || targetType == typeof(SolidAngle?))) { message += $"{GetType().Name} does not support converting to {targetType.Name}"; } if (message != string.Empty) { message = message.TrimEnd('\r', '\n'); if (Is.DesignMode) { throw new InvalidOperationException(message); } return(message); } if (value == null) { return(null); } if (value is double) { return(new SolidAngle((double)value, this.unit.Value)); } var text = value as string; if (string.IsNullOrEmpty(text)) { return(null); } var unitInput = UnitInput ?? Wpf.UnitInput.ScalarOnly; switch (unitInput) { case Wpf.UnitInput.ScalarOnly: { double d; if (double.TryParse(text, NumberStyles.Float, culture, out d)) { return(new SolidAngle(d, this.unit.Value)); } SolidAngle result; if (SolidAngle.TryParse(text, NumberStyles.Float, culture, out result)) { return($"#{text}#"); // returning modified text so that TypeConverter fails and we get an error } return(text); // returning raw to trigger error } case Wpf.UnitInput.SymbolAllowed: { double d; int pos = 0; WhiteSpaceReader.TryRead(text, ref pos); if (DoubleReader.TryRead(text, ref pos, NumberStyles.Float, culture, out d)) { WhiteSpaceReader.TryRead(text, ref pos); if (pos == text.Length) { return(new SolidAngle(d, this.unit.Value)); } } goto case Wpf.UnitInput.SymbolRequired; } case Wpf.UnitInput.SymbolRequired: { SolidAngle result; if (SolidAngle.TryParse(text, NumberStyles.Float, culture, out result)) { return(result); } return(text); } default: throw new ArgumentOutOfRangeException(); } }