Example #1
0
        public void GetSignature_returns_the_expected_result_for_constructors(string ctorDefinition, string expectedSignature)
        {
            // ARRANGE
            var cs = $@"
                using System;
                using System.IO;
                using System.Collections.Generic;

                public class Class1
                {{
                    {ctorDefinition}
                    {{ }}
                }}
            ";

            using var assembly = Compile(cs);

            var method = assembly.MainModule.Types
                         .Single(x => x.Name == "Class1")
                         .Methods
                         .Single(x => x.IsConstructor);

            // ACT
            var actualSignature = SignatureFormatter.GetSignature(method);

            // ASSERT
            Assert.Equal(expectedSignature, actualSignature);
        }
Example #2
0
        public void GetSignature_returns_the_expected_result_for_method_ids(string methodDefinition, string expectedSignature)
        {
            // ARRANGE
            var cs = $@"
                using System;

                public class Class1
                {{
                    {methodDefinition} => throw new NotImplementedException();
                }}
            ";

            using var assembly = Compile(cs);

            var method = assembly.MainModule.Types
                         .Single(x => x.Name == "Class1")
                         .Methods
                         .Single(x => !x.IsConstructor);


            var methodId = method.ToMethodId();

            // ACT
            var actualSignature = SignatureFormatter.GetSignature(methodId);

            // ASSERT
            Assert.Equal(expectedSignature, actualSignature);
        }
Example #3
0
        public void GetSignature_returns_the_expected_result_for_operators_as_method_ids(string methodName, string expectedSignature)
        {
            // ARRANGE
            var cs = $@"
                using System;

                public class Class1
                {{
                    public static Class1 operator +(Class1 left, Class1 right) => throw new NotImplementedException();

                    public static implicit operator string(Class1 instance) => throw new NotImplementedException();        
                }}
            ";

            using var assembly = Compile(cs);

            var method = assembly.MainModule.Types
                         .Single(x => x.Name == "Class1")
                         .Methods
                         .Single(x => x.Name == methodName);


            var methodId = method.ToMethodId();

            // ACT
            var actualSignature = SignatureFormatter.GetSignature(methodId);

            // ASSERT
            Assert.Equal(expectedSignature, actualSignature);
        }
Example #4
0
        public void GetSignature_returns_the_expected_result_for_indexers_as_property_id(string indexerDefinition, string expectedSignature)
        {
            // ARRANGE
            var cs = $@"
                using System;

                public class Class1
                {{
                    {indexerDefinition} => throw new NotImplementedException();
                }}
            ";

            using var assembly = Compile(cs);

            var property = assembly.MainModule.Types
                           .Single(x => x.Name == "Class1")
                           .Properties
                           .Single();

            var propertyId = property.ToPropertyId();

            // ACT
            var actualSignature = SignatureFormatter.GetSignature(propertyId);

            // ASSERT
            Assert.Equal(expectedSignature, actualSignature);
        }
Example #5
0
        public MdSpan GetMdSpan(MemberId id, bool noLink = false)
        {
            switch (id)
            {
            case TypeId typeId:
                return(GetMdSpan(typeId, noLink));

            case MethodId methodId:
                if (noLink)
                {
                    return(SignatureFormatter.GetSignature(methodId));
                }
                else
                {
                    return(CreateLink(methodId, SignatureFormatter.GetSignature(methodId)));
                }

            case PropertyId propertyId:
                if (noLink)
                {
                    return(SignatureFormatter.GetSignature(propertyId));
                }
                else
                {
                    return(CreateLink(propertyId, SignatureFormatter.GetSignature(propertyId)));
                }

            case TypeMemberId typeMemberId:
                if (noLink)
                {
                    return(typeMemberId.Name);
                }
                else
                {
                    return(CreateLink(typeMemberId, typeMemberId.Name));
                }

            case NamespaceId namespaceId:
                if (noLink)
                {
                    return(namespaceId.Name);
                }
                else
                {
                    return(CreateLink(namespaceId, namespaceId.Name));
                }

            default:
                return(MdEmptySpan.Instance);
            }
        }