Skip to content

Commit

Permalink
Put in a temp fix after net 7 sdk broke some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxive committed Feb 24, 2023
1 parent db4ff81 commit abf49c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Zoxive.MemoizeSourceGenerator/MemoizedClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Zoxive.MemoizeSourceGenerator
{
internal static class MemoizedClass
{
private static string Prefix = "_sg_";

public static string Generate(MemoizerCall call)
{
var fullInterfaceName = call.InterfaceType.ToDisplayString();
Expand Down Expand Up @@ -57,13 +59,13 @@ public class {call.ClassName} : {fullInterfaceName}
sb.Append("async ");
}
sb.Append($"{returnType} {methodName}(");
method.WriteParameters(sb, writeType: true, prefix: "__");
method.WriteParameters(sb, writeType: true, prefix: Prefix);
sb.AppendLine(")");
sb.AppendLine("\t\t{");

if (method.PartitionedParameter != null)
{
sb.AppendLine($"\t\t\tvar cache = _cacheFactory.GetOrCreatePartition(__{method.PartitionedParameter.Name});");
sb.AppendLine($"\t\t\tvar cache = _cacheFactory.GetOrCreatePartition({Prefix}{method.PartitionedParameter.Name});");
}
else
{
Expand All @@ -75,7 +77,7 @@ public class {call.ClassName} : {fullInterfaceName}
{
sb.Append(",");
}
method.WriteParameters(sb, prefix: "__");
method.WriteParameters(sb, prefix: Prefix);
sb.AppendLine(");");
sb.Append($"\t\t\tif (cache.TryGetValue<{method.TypeInCache}>(key, out var returnValue)");

Expand All @@ -101,7 +103,7 @@ public class {call.ClassName} : {fullInterfaceName}
sb.Append("await ");
}
sb.Append($"_impl.{methodName}(");
method.WriteParameters(sb, prefix: "__");
method.WriteParameters(sb, prefix: Prefix);
sb.AppendLine(");");

sb.AppendLine();
Expand Down Expand Up @@ -167,14 +169,14 @@ private static void GenerateArgStruct(MemoizedMethodMember method, StringBuilder
{
sb.Append(",");
}
method.WriteParameters(sb, writeType: true, prefix: "__");
method.WriteParameters(sb, writeType: true, prefix: Prefix);

sb.AppendLine(")");
sb.AppendLine("\t\t\t{");
sb.AppendLine($"\t\t\t\tPartitionKey = partitionKey;");
foreach (var arg in method.Parameters)
{
sb.AppendLine($"\t\t\t\t_{arg.Name} = __{arg.Name};");
sb.AppendLine($"\t\t\t\t_{arg.Name} = {Prefix}{arg.Name};");
}

sb.AppendLine("\t\t\t}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ private MemoizedMethodMemberArgument(IParameterSymbol parameterSymbol, bool part
PartitionsCache = partitionsCache;
Name = parameterSymbol.Name;
ArgType = parameterSymbol.ToDisplayString();

// Hack fix
// https://github.com/dotnet/roslyn/pull/65606
// ToDisplayString() has changed to include the variable name.. and theres no way to turn it off.
// (The methods are Internal Only to customize SymbolDisplayFormat)
if (ArgType.Contains(' '))
ArgType = ArgType.Split(' ').First();

IsNullable = parameterSymbol.NullableAnnotation == NullableAnnotation.Annotated;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.0.9</Version>
<Version>0.0.10</Version>
<AssemblyName>Zoxive.MemoizeSourceGenerator</AssemblyName>
<Description>Compiled time generate memoized services</Description>
<PackageTags>sourcegenerator;memoize;cache</PackageTags>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.102",
"rollForward": "latestPatch"
"version": "6.0.309",
"rollForward": "latestPatch"
}
}

0 comments on commit abf49c8

Please sign in to comment.