public void Should_work_with_tryparse_method_provided_by_ParseMethodFinder() { var parser = new TryParseMethodParser(ParseMethodFinder.FindTryParseMethod(typeof(int))); parser.TryParse("12", out var value).Should().BeTrue(); value.Should().Be(12); }
public SettingsBindingResult <T> Bind(ISettingsNode rawSettings) { var tryParseMethod = ParseMethodFinder.FindTryParseMethod(typeof(T)); if (tryParseMethod != null) { return(new PrimitiveBinder <T>(new TryParseMethodParser(tryParseMethod)).Bind(rawSettings)); } var parseMethod = ParseMethodFinder.FindParseMethod(typeof(T)); if (parseMethod != null) { return(new PrimitiveBinder <T>(new ParseMethodParser(parseMethod)).Bind(rawSettings)); } return(SettingsBindingResult.Error <T>($"Failed to find a '{nameof(int.TryParse)}' or '{nameof(int.Parse)}' method on '{typeof(T)}' type.")); }
public void Should_not_detect_methods_where_there_are_none() { ParseMethodFinder.FindParseMethod(GetType()).Should().BeNull(); ParseMethodFinder.FindTryParseMethod(GetType()).Should().BeNull(); }
public void Should_detect_tryparse_method() { ParseMethodFinder.FindTryParseMethod(typeof(int)).Should().NotBeNull(); ParseMethodFinder.FindTryParseMethod(typeof(Guid)).Should().NotBeNull(); ParseMethodFinder.FindTryParseMethod(typeof(IPAddress)).Should().NotBeNull(); }