public override string ToString() { var result = new StringBuilder(); if (MethodBase is MethodInfo info) { if (info.ReturnType != typeof(void)) { result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" "); } else { result.Append("void "); } } result.Append(MethodBase.Name); if (MethodBase.IsGenericMethod) { var generic = ((MethodInfo)MethodBase).GetGenericMethodDefinition(); result .Append("<") .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name))) .Append(">"); } result .Append("(") .Append(Arguments.ToString()) .Append(")"); return(result.ToString()); }
public void Ctor_ValueIsGuid_SetsValue() { var expected = Guid.NewGuid().ToString(); var value = new Stringly <Guid>(expected).Value; Assert.That(value, Is.EqualTo(expected)); }
public void ImplicitString_BooleanValue_ReturnsStringPassed() { var expected = "FALSE"; string result = new Stringly <bool>(expected); Assert.That(result, Is.EqualTo(expected)); }
public void ToString_BooleanValue_ReturnsStringPassed() { var expected = "FALSE"; var result = new Stringly <bool>(expected).ToString(); Assert.That(result, Is.EqualTo(expected)); }
public void Ctor_ValueIsInt_SetsValue() { var expected = 42.ToString(); var value = new Stringly <int>(expected).Value; Assert.That(value, Is.EqualTo(expected)); }
public override string ToString() { var result = new StringBuilder(); if (MethodBase is MethodInfo info) { if (info.ReturnType != typeof(void)) { result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" "); } else { result.Append("void "); } } if (MethodBase.IsSpecialName) { if (MethodBase.Name.StartsWith("get_", StringComparison.Ordinal) || MethodBase.Name.StartsWith("set_", StringComparison.Ordinal)) { result.Append(MethodBase.Name.Substring(4)); } else if (MethodBase.Name.StartsWith("add_", StringComparison.Ordinal)) { result.Append(MethodBase.Name.Substring(4) + " += "); } else if (MethodBase.Name.StartsWith("remove_", StringComparison.Ordinal)) { result.Append(MethodBase.Name.Substring(7) + " -= "); } } else { result.Append(MethodBase.Name); } if (MethodBase.IsGenericMethod) { var generic = ((MethodInfo)MethodBase).GetGenericMethodDefinition(); result .Append("<") .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name))) .Append(">"); } // TODO: render indexer arguments? if (!MethodBase.IsSpecialName) { return(result .Append("(") .Append(Arguments.ToString()) .Append(")") .ToString()); } return(result.ToString()); }
public void StringlyComplexType_GivenAString_ValidatesAndCreatesTypeCorrectly() { Assert.That(_service.CalculateArea(new Stringly <Size>("10x10")), Is.EqualTo(100)); Size size = new Stringly <Size>("42x1337"); Assert.That(size.Width, Is.EqualTo(42)); Assert.That(size.Height, Is.EqualTo(1337)); Assert.Throws <ArgumentOutOfRangeException>( () => new Stringly <Size>("w:10 h:10")); }
public override string ToString() { var result = new StringBuilder(); if (setup.MethodBase is MethodInfo info) { if (info.ReturnType != typeof(void)) { result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" "); } else { result.Append("void "); } } result.Append(setup.MethodBase.Name); if (setup.MethodBase.IsGenericMethod) { var generic = ((MethodInfo)setup.MethodBase).GetGenericMethodDefinition(); result .Append("<") .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name))) .Append(">"); } var parameters = setup.MethodBase.GetParameters(); return(result .Append("(") .Append(string.Join(", ", parameters.Select((p, i) => Stringly.ToTypeName(p.ParameterType) + " " + p.Name + " = " + matchers[i].ToString() ))) .Append(")") .ToString()); }
public void Ctor_ValueMatchesRegex_CreatesComplexType() { DigitsOnly stringly = new Stringly <DigitsOnly>("0000"); Assert.That(stringly.Digits.Count, Is.EqualTo(4)); }
public void Ctor_TypedThatThrows_ThrowsArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>( () => { Stringly <TypeWithTypeParseThatThrows> value = "test"; }); }
public override string ToString() => "Any<" + Stringly.ToTypeName(ArgumentType) + ">";
public static int Increment(Stringly <int> digits) { return(digits + 1); }
public override string ToString() { var result = new StringBuilder(); if (invocation.MethodBase is MethodInfo info) { if (info.ReturnType != typeof(void)) { result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" "); } else { result.Append("void "); } } if (invocation.MethodBase.IsSpecialName) { if (invocation.MethodBase.Name.StartsWith("get_", StringComparison.Ordinal) || invocation.MethodBase.Name.StartsWith("set_", StringComparison.Ordinal)) { result.Append(invocation.MethodBase.Name.Substring(4)); } else if (invocation.MethodBase.Name.StartsWith("add_", StringComparison.Ordinal)) { result.Append(invocation.MethodBase.Name.Substring(4) + " += "); } else if (invocation.MethodBase.Name.StartsWith("remove_", StringComparison.Ordinal)) { result.Append(invocation.MethodBase.Name.Substring(7) + " -= "); } } else { result.Append(invocation.MethodBase.Name); } if (invocation.MethodBase.IsGenericMethod) { var generic = ((MethodInfo)invocation.MethodBase).GetGenericMethodDefinition(); result .Append("<") .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name))) .Append(">"); } var parameters = invocation.MethodBase.GetParameters(); // TODO: render indexer arguments? if (!invocation.MethodBase.IsSpecialName) { return(result .Append("(") .Append(string.Join(", ", parameters.Select((p, i) => (p.IsOut ? "out " : (p.ParameterType.IsByRef ? "ref " : "")) + Stringly.ToTypeName(p.ParameterType) + " " + p.Name + (p.IsOut ? "" : (" = " + matchers[i])) ))) .Append(")") .ToString()); } return(result.ToString()); }
public void Ctor_GivenAString_ThrowsArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>( () => { Stringly <TypeWithoutTryParseMethod> cat = "nyan"; }); }
internal void DontWantToNewStringly(Stringly <RecordId> recordId) { RecordId id = recordId; }