Fixed multi-dimension argument / return type (#55)

* Fixed multi dimension array arguments

* .

* .

* .

* ,
This commit is contained in:
Stef Heyenrath
2023-02-21 19:10:03 +01:00
committed by GitHub
parent 196db037ab
commit 65d1d801ce
8 changed files with 36 additions and 8 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
rem https://github.com/StefH/GitHubReleaseNotes
SET version=0.0.30
SET version=0.0.31
GitHubReleaseNotes --output "ReleaseNotes.md" --skip-empty-releases --exclude-labels question invalid doc --version %version%
@@ -9,7 +9,7 @@ internal static class MethodParameterBuilder
public static string Build(IParameterSymbol parameterSymbol, string? type)
{
var stringBuilder = new StringBuilder();
if (type is { })
if (type is not null)
{
stringBuilder.Append(parameterSymbol.GetAttributesPrefix()); // "" or [NotNullWhen(true)]
stringBuilder.Append(parameterSymbol.GetParamsPrefix()); // "" or "params "
@@ -11,6 +11,8 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators;
internal abstract class BaseGenerator
{
private const string Star = "*";
protected readonly Context Context;
protected readonly bool SupportsNullable;
@@ -150,7 +152,7 @@ internal abstract class BaseGenerator
}
isReplaced = true;
return existing.FullInterfaceName;
return FixType(existing.FullInterfaceName);
}
ITypeSymbol[] typeArguments;
@@ -164,7 +166,7 @@ internal abstract class BaseGenerator
}
else
{
return typeSymbolAsString;
return FixType(typeSymbolAsString);
}
var propertyTypeAsStringToBeModified = typeSymbolAsString;
@@ -185,7 +187,7 @@ internal abstract class BaseGenerator
}
}
return propertyTypeAsStringToBeModified;
return FixType(propertyTypeAsStringToBeModified);
}
protected bool TryGetNamedTypeSymbolByFullName(TypeKind kind, string name, IEnumerable<string> usings, [NotNullWhen(true)] out ClassSymbol? classSymbol)
@@ -258,4 +260,13 @@ internal abstract class BaseGenerator
}
return extendsProxyClasses;
}
/// <summary>
/// Issue 54
/// double[*,*] --> double[,]
/// </summary>
protected static string FixType(string type)
{
return type.Replace(Star, string.Empty);
}
}
@@ -235,6 +235,7 @@ using System;
str.AppendLine(" {");
foreach (var ps in method.Parameters)
{
var type = FixType(ps.Type.ToString());
string normalOrMap = $" = {ps.GetSanitizedName()}";
if (ps.RefKind == RefKind.Out)
{
@@ -245,11 +246,11 @@ using System;
_ = GetParameterType(ps, out var isReplaced); // TODO : response is not used?
if (isReplaced)
{
normalOrMap = $" = Mapster.TypeAdapter.Adapt<{ps.Type}>({ps.GetSanitizedName()})";
normalOrMap = $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()})";
}
}
str.AppendLine($" {ps.Type} {ps.GetSanitizedName()}_{normalOrMap};");
str.AppendLine($" {type} {ps.GetSanitizedName()}_{normalOrMap};");
}
var methodName = method.GetMethodNameWithOptionalTypeParameters();
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.0.30</Version>
<Version>0.0.31</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{12344228-91F4-4502-9595-39584E5ABB34}</ProjectGuid>
<LangVersion>10</LangVersion>
@@ -54,6 +54,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source
void In_Out_Ref1(in int a, out int b, ref int c);
double[,] Out_MultiDimensionIssue54(out double[,] x);
bool Generic2<T1, T2>(int x, T1 t1, T2 t2) where T1 : struct where T2 : class, new();
System.Threading.Tasks.Task Method1Async();
@@ -110,6 +110,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source
b = b_;
}
public double[,] Out_MultiDimensionIssue54(out double[,] x)
{
double[,] x_;
var result_692039870 = _Instance.Out_MultiDimensionIssue54(out x_);
x = x_;
return result_692039870;
}
public bool Generic2<T1, T2>(int x, T1 t1, T2 t2) where T1 : struct where T2 : class, new()
{
int x_ = x;
@@ -85,6 +85,12 @@ namespace ProxyInterfaceSourceGeneratorTests.Source
b = 1;
}
public double[,] Out_MultiDimensionIssue54(out double[,] x)
{
x = new double[0, 0];
return x;
}
public bool Generic2<T1, T2>(int x, T1 t1, T2 t2)
where T1 : struct
where T2 : class, new()