Unified · Split
| @@ -22,6 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | //****************************************************************************************************** |
| 23 | 23 | |
| 24 | 24 | using System; |
| 25 | +using GSF; | |
| 25 | 26 | using GSF.Data; |
| 26 | 27 | using GSF.TimeSeries.UI; |
| 27 | 28 | |
| @@ -55,7 +56,7 @@ namespace PowerCalculations.PowerMultiCalculator · 27 unmodified lines | ||
| 55 | 56 | measurement.SignalTypeID, measurement.SignalReference, measurement.Adder, measurement.Multiplier, measurement.Description.ToNotNull(), |
| 56 | 57 | database.Bool(measurement.Enabled), CommonFunctions.CurrentUser, database.UtcNow, CommonFunctions.CurrentUser, database.UtcNow); |
| 57 | 58 | |
| 58 | − measurement.SignalID = Guid.Parse(database.ExecuteScalar<object>(Guid.Empty, "SELECT SignalID FROM Measurement WHERE PointTag={0}", measurement.PointTag).ToString()); | |
| 59 | + measurement.SignalID = database.ExecuteScalar<Guid>("SELECT SignalID FROM Measurement WHERE PointTag={0}", measurement.PointTag); | |
| 59 | 60 | } |
| 60 | 61 | else |
| 61 | 62 | { |
| @@ -684,7 +684,21 @@ namespace GSF.Data · 683 unmodified lines | ||
| 684 | 684 | |
| 685 | 685 | // Nullable types cannot be used in type conversion, but we can use Nullable.GetUnderlyingType() |
| 686 | 686 | // to determine whether the type is nullable and convert to the underlying type instead |
| 687 | − return (T)Convert.ChangeType(value, Nullable.GetUnderlyingType(type) ?? type); | |
| 687 | + type = Nullable.GetUnderlyingType(type) ?? type; | |
| 688 | + | |
| 689 | + // Handle Guids | |
| 690 | + if (type == typeof(Guid)) | |
| 691 | + return (T)(object)System.Guid.Parse(value.ToString()); | |
| 692 | + | |
| 693 | + // Handle string types that may have a converter function (e.g., Enums) | |
| 694 | + if (value.GetType() == typeof(string)) | |
| 695 | + return value.ToString().ConvertToType<T>(type); | |
| 696 | + | |
| 697 | + // Handle native types | |
| 698 | + if (typeof(IConvertible).IsAssignableFrom(value.GetType())) | |
| 699 | + return (T)Convert.ChangeType(value, type); | |
| 700 | + | |
| 701 | + return (T)value; | |
| 688 | 702 | } |
| 689 | 703 | |
| 690 | 704 | /// <summary> |
| @@ -206,12 +206,8 @@ namespace GSF · 205 unmodified lines | ||
| 206 | 206 | try |
| 207 | 207 | { |
| 208 | 208 | // Handle booleans as a special case to allow numeric entries as well as true/false |
| 209 | − if (type.IsAssignableFrom(typeof(bool))) | |
| 210 | − return (T)((object)value.ParseBoolean()); | |
| 211 | − | |
| 212 | − // This is faster for native types than using type converter... | |
| 213 | − if (type.IsAssignableFrom(typeof(IConvertible))) | |
| 214 | − return (T)Convert.ChangeType(value, type, culture); | |
| 209 | + if (type == typeof(bool)) | |
| 210 | + return (T)(object)value.ParseBoolean(); | |
| 215 | 211 | |
| 216 | 212 | // Handle objects that have type converters (e.g., Enum, Color, Point, etc.) |
| 217 | 213 | TypeConverter converter = TypeDescriptor.GetConverter(type); |