Properly parse type for methods with generic arguments.

Added some test cases.
This commit is contained in:
Cristian Stoica 2017-05-03 00:33:57 +03:00 коммит произвёл Marek Safar
Родитель fc96e216d5
Коммит d7fd8f607d
6 изменённых файлов: 140 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,17 @@
using NUnit.Framework;
namespace MoMA.Analyzer.Methods.Tests
{
[TestFixture]
public class MethodTests
{
[TestCase("System.Int32 MyCompany.MyProduct.MyModule::MyMethod(System.String)", "int MyMethod(string)")]
[TestCase("System.Int32 MyCompany.MyProduct.MyModule::MyMethod(System.String, System.Collections.Generic.IDictionary`2<System.String,System.Object>,System.String,System.Object)", "int MyMethod(string, IDictionary`2<string, Object>, string, Object)")]
public void ToString(string methodSignature, string expectedResult)
{
var method = new Method(methodSignature);
Assert.AreEqual(expectedResult, method.ToString());
}
}
}

Просмотреть файл

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MoMA.Analyzer.Tests</RootNamespace>
<AssemblyName>MoMA.Analyzer.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\moma\packages\NUnit.3.6.1\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Methods\MethodTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MoMA.Analyzer\MoMA.Analyzer.csproj">
<Project>{cc12f142-c92f-4ad0-aea3-d94f661c557b}</Project>
<Name>MoMA.Analyzer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MoMA.Analyzer.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoMA.Analyzer.Tests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f9fa4aab-f02b-4180-a436-45ff4a657ad9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.6.1" targetFramework="net40" />
</packages>

Просмотреть файл

@ -173,6 +173,14 @@ namespace MoMA.Analyzer
case "System.Byte":
return "byte";
}
if (type.Contains("<"))
{
return string.Format("{0}<{1}", ConvertType(type.Substring(0, type.IndexOf("<"))), ConvertType(type.Substring(type.IndexOf("<") + 1)));
}
if (type.EndsWith(">"))
{
return string.Format("{0}>", ConvertType(type.Substring(0, type.IndexOf(">"))));
}
return type.Substring (type.LastIndexOf (".") + 1);
}

Просмотреть файл

@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoMA.Analyzer", "MoMA.Analy
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoMAExtractor", "MoMAExtractor\MoMAExtractor.csproj", "{64DE84A1-C274-4875-84F2-FCA7B24104D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoMA.Analyzer.Tests", "MoMA.Analyzer.Tests\MoMA.Analyzer.Tests.csproj", "{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -35,6 +37,10 @@ Global
{64DE84A1-C274-4875-84F2-FCA7B24104D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64DE84A1-C274-4875-84F2-FCA7B24104D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64DE84A1-C274-4875-84F2-FCA7B24104D8}.Release|Any CPU.Build.0 = Release|Any CPU
{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9FA4AAB-F02B-4180-A436-45FF4A657AD9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE