Beispiel #1
0
        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());
        }
Beispiel #2
0
        public void Ctor_ValueIsGuid_SetsValue()
        {
            var expected = Guid.NewGuid().ToString();

            var value = new Stringly <Guid>(expected).Value;

            Assert.That(value, Is.EqualTo(expected));
        }
Beispiel #3
0
        public void ImplicitString_BooleanValue_ReturnsStringPassed()
        {
            var expected = "FALSE";

            string result = new Stringly <bool>(expected);

            Assert.That(result, Is.EqualTo(expected));
        }
Beispiel #4
0
        public void ToString_BooleanValue_ReturnsStringPassed()
        {
            var expected = "FALSE";

            var result = new Stringly <bool>(expected).ToString();

            Assert.That(result, Is.EqualTo(expected));
        }
Beispiel #5
0
        public void Ctor_ValueIsInt_SetsValue()
        {
            var expected = 42.ToString();

            var value = new Stringly <int>(expected).Value;

            Assert.That(value, Is.EqualTo(expected));
        }
Beispiel #6
0
        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());
        }
Beispiel #7
0
        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"));
        }
Beispiel #8
0
        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());
        }
Beispiel #9
0
        public void Ctor_ValueMatchesRegex_CreatesComplexType()
        {
            DigitsOnly stringly = new Stringly <DigitsOnly>("0000");

            Assert.That(stringly.Digits.Count, Is.EqualTo(4));
        }
Beispiel #10
0
 public void Ctor_TypedThatThrows_ThrowsArgumentOutOfRangeException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => { Stringly <TypeWithTypeParseThatThrows> value = "test"; });
 }
Beispiel #11
0
 public override string ToString() => "Any<" + Stringly.ToTypeName(ArgumentType) + ">";
Beispiel #12
0
 public static int Increment(Stringly <int> digits)
 {
     return(digits + 1);
 }
Beispiel #13
0
        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());
        }
Beispiel #14
0
 public void Ctor_GivenAString_ThrowsArgumentOutOfRangeException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => { Stringly <TypeWithoutTryParseMethod> cat = "nyan"; });
 }
Beispiel #15
0
 internal void DontWantToNewStringly(Stringly <RecordId> recordId)
 {
     RecordId id = recordId;
 }