Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZLoggerMessageAttribute without parameters generate CS1522 warnings #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ZLogger.Generator/ZLoggerGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,50 +253,60 @@ public void WriteJsonParameterKeyValues(global::System.Text.Json.Utf8JsonWriter
sb.AppendLine($$"""
public ReadOnlySpan<byte> GetParameterKey(int index)
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return \"{x.LinkedMessageSegment.GetPropertyName()}\"u8;")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}

public string GetParameterKeyAsString(int index)
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return \"{x.LinkedMessageSegment.GetPropertyName()}\";")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}

public object GetParameterValue(int index)
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return this.{x.LinkedMessageSegment.NameParameter}!;")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}

public T GetParameterValue<T>(int index)
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return Unsafe.As<{x.Symbol.Type.ToFullyQualifiedFormatString()}, T>(ref Unsafe.AsRef(in this.{x.LinkedMessageSegment.NameParameter}));")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}

public Type GetParameterType(int index)
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return typeof({x.Symbol.Type.ToFullyQualifiedFormatString()});")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}
Expand All @@ -317,10 +327,12 @@ void EmitKeyValuePairEnumerator(LogMethodDeclaration method)
{
get
{
{{If(methodParameters.Length > 0, $$"""
switch (index)
{
{{ForEachLine(" ", methodParameters, (x, i) => $"case {i}: return new(\"{x.LinkedMessageSegment.GetPropertyName()}\", {x.LinkedMessageSegment.NameParameter});")}}
}
""")}}
global::ZLogger.Internal.CodeGeneratorUtil.ThrowArgumentOutOfRangeException();
return default!;
}
Expand Down