diff --git a/code/Binary.SourceGeneration/Contexts/CollectionConverterContext.cs b/code/Binary.SourceGeneration/Contexts/CollectionConverterContext.cs index e193c83f..dd150350 100644 --- a/code/Binary.SourceGeneration/Contexts/CollectionConverterContext.cs +++ b/code/Binary.SourceGeneration/Contexts/CollectionConverterContext.cs @@ -137,7 +137,7 @@ private void AppendConverterCreatorBody() for (var i = 0; i < elements.Length; i++) { var element = elements[i]; - AppendAssignConverterExplicit(element, $"cvt{i}", GetConverterTypeFullName(i), GetTypeFullName(i)); + AppendAssignConverterExplicit(element, $"cvt{i}", GetTypeFullName(i)); CancellationToken.ThrowIfCancellationRequested(); } Output.AppendIndent(3, $"var converter = new {OutputConverterTypeName}(", ");", elements.Length, x => $"cvt{x}"); diff --git a/code/Binary.SourceGeneration/Contexts/GenericConverterContext.cs b/code/Binary.SourceGeneration/Contexts/GenericConverterContext.cs index 294e94d2..88027c27 100644 --- a/code/Binary.SourceGeneration/Contexts/GenericConverterContext.cs +++ b/code/Binary.SourceGeneration/Contexts/GenericConverterContext.cs @@ -26,7 +26,7 @@ private void AppendConverterCreatorBody() for (var i = 0; i < elements.Length; i++) { types.Add(GetTypeFullName(i)); - AppendAssignConverterExplicit(elements[i], $"cvt{i}", GetConverterTypeFullName(i), GetTypeFullName(i)); + AppendAssignConverterExplicit(elements[i], $"cvt{i}", GetTypeFullName(i)); CancellationToken.ThrowIfCancellationRequested(); } Output.AppendIndent(3, $"var converter = Mikodev.Binary.Generator.Get{info.TypeName}Converter<{string.Join(", ", types)}>(", ");", elements.Length, x => $"cvt{x}"); diff --git a/code/Binary.SourceGeneration/Contexts/InlineArrayConverterContext.cs b/code/Binary.SourceGeneration/Contexts/InlineArrayConverterContext.cs index bc963dea..baa9fc48 100644 --- a/code/Binary.SourceGeneration/Contexts/InlineArrayConverterContext.cs +++ b/code/Binary.SourceGeneration/Contexts/InlineArrayConverterContext.cs @@ -59,7 +59,7 @@ private void AppendConverterCreatorBody() { var info = this.info; var element = info.ElementType; - AppendAssignConverterExplicit(element, "cvt0", GetConverterTypeFullName(0), GetTypeFullName(0)); + AppendAssignConverterExplicit(element, "cvt0", GetTypeFullName(0)); Output.AppendIndent(3, $"var converter = new {OutputConverterTypeName}(cvt0);"); } diff --git a/code/Binary.SourceGeneration/Contexts/NamedObjectConverterContext.cs b/code/Binary.SourceGeneration/Contexts/NamedObjectConverterContext.cs index a7a3e044..3dda4af7 100644 --- a/code/Binary.SourceGeneration/Contexts/NamedObjectConverterContext.cs +++ b/code/Binary.SourceGeneration/Contexts/NamedObjectConverterContext.cs @@ -101,7 +101,7 @@ private void AppendConverterCreatorBody() var members = this.members; Output.AppendIndent(3, $"var names = new string[] {{ ", $" }};", members.Length, x => members[x].NamedKeyLiteral); Output.AppendIndent(3, $"var optional = new bool[] {{ ", $" }};", members.Length, x => members[x].IsOptional ? "true" : "false"); - Output.AppendIndent(3, $"var encoding = (Mikodev.Binary.Converter)context.GetConverter(typeof(string));"); + Output.AppendIndent(3, $"var encoding = Mikodev.Binary.GeneratorContextExtensions.GetConverter(context);"); for (var i = 0; i < members.Length; i++) { var member = members[i]; diff --git a/code/Binary.SourceGeneration/SymbolConverterContext.cs b/code/Binary.SourceGeneration/SymbolConverterContext.cs index adbcf632..6f85c9f0 100644 --- a/code/Binary.SourceGeneration/SymbolConverterContext.cs +++ b/code/Binary.SourceGeneration/SymbolConverterContext.cs @@ -33,7 +33,7 @@ protected SymbolConverterContext(SourceGeneratorContext context, SourceGenerator var output = Symbols.GetOutputFullName(symbol); this.context = context; this.tracker = tracker; - this.fullNameCache = new Dictionary(); + this.fullNameCache = []; Symbol = symbol; SymbolTypeFullName = context.GetTypeFullName(symbol); SymbolConverterTypeFullName = context.GetConverterTypeFullName(symbol); @@ -90,9 +90,9 @@ protected void AppendAssignConverterExplicitConverterCreator(ITypeSymbol creator CancellationToken.ThrowIfCancellationRequested(); } - protected void AppendAssignConverterExplicit(ITypeSymbol member, string variableName, string converterTypeAlias, string memberTypeAlias) + protected void AppendAssignConverterExplicit(ITypeSymbol member, string variableName, string memberTypeAlias) { - Output.AppendIndent(3, $"var {variableName} = ({converterTypeAlias})context.GetConverter(typeof({memberTypeAlias}));"); + Output.AppendIndent(3, $"var {variableName} = Mikodev.Binary.GeneratorContextExtensions.GetConverter<{memberTypeAlias}>(context);"); this.tracker.Invoke(member); CancellationToken.ThrowIfCancellationRequested(); } @@ -104,7 +104,7 @@ protected void AppendAssignConverter(SymbolMemberInfo member, string variableNam else if (Symbols.GetConverterCreatorType(this.context, member.Symbol) is { } creator) AppendAssignConverterExplicitConverterCreator(creator, variableName, converterTypeAlias, memberTypeAlias); else - AppendAssignConverterExplicit(member.Type, variableName, converterTypeAlias, memberTypeAlias); + AppendAssignConverterExplicit(member.Type, variableName, memberTypeAlias); } protected abstract void Handle();