/// <summary> /// Get the string for a given key and convert to the desired type /// </summary> /// <param name="key">case insensitive key to fetch</param> /// <param name="default">An optional function to provide the default if the key is missing</param> /// <typeparam name="T">The type to convert to</typeparam> /// <returns>The converted value</returns> /// <exception cref="KeyNotFoundException">Key is not present and no default was provided</exception> public T Get <T>(string key, Func <T> @default = null) { var found = SettingsDictionary .TryGetValue(key, Environment, out var result); if (found) { return(_converter.Convert <T>(result)); } else if (@default != null) { return(@default()); } else { throw new KeyNotFoundException(); } }
private void ApplyStringConverter(IStringConverter converter) { int startPos = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Offset; int length = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Length; if (startPos >= 0) { string selection = ActiveTextAreaControl.SelectionManager.SelectedText; string newSelection = converter.Convert(startPos, selection); if ((newSelection != null) && (selection != newSelection)) { Document.Replace(startPos, selection.Length, newSelection); SetSelection(startPos, newSelection.Length); } } }
private void ApplyStringConverter(IStringConverter converter) { int startPos = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Offset; int length = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Length; if (startPos >= 0) { string selection = ActiveTextAreaControl.SelectionManager.SelectedText; string newSelection = converter.Convert(startPos, selection); if ((newSelection != null) && (selection != newSelection)) { Document.Replace(startPos, selection.Length, newSelection); SetSelection(startPos, newSelection.Length); } } }
public void Convert_Should_Return_IStringConverter(string arg) { Assert.That(_converter.Convert(arg), Is.Not.Null.And.InstanceOf <IStringConverter>()); }
public void ConvertTimeSpan() { var timeSpan = TimeSpan.FromMinutes(42); var asString = timeSpan.ToString(); var parsed = _converter.Convert <TimeSpan>(asString); Assert.AreEqual(timeSpan, parsed); }