Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 8 additions & 11 deletions src/Dapper.AOT.Analyzers/CodeAnalysis/DapperAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper.Internal;
using Dapper.CodeAnalysis.Model;
using Dapper.Internal.Roslyn;
using Dapper.SqlAnalysis;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -872,10 +873,10 @@ enum ParameterMode
}
}

ImmutableArray<CommandProperty> cmdProps;
EquatableArray<CommandProperty> cmdProps = default;
if (cmdPropsCount != 0)
{
var builder = ImmutableArray.CreateBuilder<CommandProperty>(cmdPropsCount);
var builder = new List<CommandProperty>(cmdPropsCount);
foreach (var attrib in methodAttribs)
{
if (IsDapperAttribute(attrib) && attrib.AttributeClass!.Name == Types.CommandPropertyAttribute
Expand All @@ -885,19 +886,15 @@ enum ParameterMode
&& attrib.ConstructorArguments[0].Value is string name
&& attrib.ConstructorArguments[1].Value is object value)
{
builder.Add(new(cmdType, name, value, location));
builder.Add(CommandProperty.Create(cmdType, name, value, location));
}
}
cmdProps = builder.ToImmutable();
cmdProps = new(builder.ToArray());
}
else
{
cmdProps = ImmutableArray<CommandProperty>.Empty;
}


return cmdProps.IsDefaultOrEmpty && rowCountHint <= 0 && rowCountHintMember is null && batchSize is null && queryColumns.IsDefault
? null : new(rowCountHint, rowCountHintMember?.Member?.Name, batchSize, cmdProps, queryColumns);
var queryColumnsModel = queryColumns.IsDefault ? default : new EquatableArray<string>(queryColumns.AsSpan().ToArray());
return cmdProps.IsEmpty && rowCountHint <= 0 && rowCountHintMember is null && batchSize is null && queryColumnsModel.IsDefault
? null : new(rowCountHint, rowCountHintMember?.Member?.Name, batchSize, cmdProps, queryColumnsModel);
}

static void ValidateParameters(MemberMap? parameters, OperationFlags flags, Action<Diagnostic> onDiagnostic)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper.Internal;
using Dapper.CodeAnalysis.Model;
using Dapper.Internal;
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;

Expand All @@ -12,7 +13,7 @@ private static bool TryWriteMultiExecImplementation(
OperationFlags commandTypeMode,
ITypeSymbol? parameterType,
string map, bool cache,
ImmutableArray<IParameterSymbol> methodParameters,
EquatableArray<MethodParam> methodParameters,
CommandFactoryState factories,
string? fixedSql,
AdditionalCommandState? additionalCommandState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper.Internal;
using Dapper.CodeAnalysis.Model;
using Dapper.Internal;
using Dapper.Internal.Roslyn;
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;
Expand All @@ -9,13 +10,13 @@ public sealed partial class DapperInterceptorGenerator
{
static void WriteSingleImplementation(
CodeWriter sb,
IMethodSymbol method,
InterceptedMethod method,
ITypeSymbol? resultType,
OperationFlags flags,
OperationFlags commandTypeMode,
ITypeSymbol? parameterType,
string map, bool cache,
in ImmutableArray<IParameterSymbol> methodParameters,
in EquatableArray<MethodParam> methodParameters,
in CommandFactoryState factories,
in RowReaderState readers,
string? fixedSql,
Expand Down Expand Up @@ -137,15 +138,7 @@ static void WriteSingleImplementation(
{
// there are some NRT oddities in Dapper itself; shim over everything
// (we know that DapperAOT has "T? {First|Single}OrDefault<T>[Async]" and "T? ExecuteScalar<T>[Async]")
bool addNullForgiving;
if (method.ReturnType.IsAsync(out var t))
{
addNullForgiving = t is not null && t.NullableAnnotation != NullableAnnotation.Annotated;
}
else
{
addNullForgiving = method.ReturnType.NullableAnnotation != NullableAnnotation.Annotated;
}
bool addNullForgiving = method.ReturnValueNeedsNullForgiving;
if (addNullForgiving)
{
sb.Append("!");
Expand All @@ -167,7 +160,7 @@ static CodeWriter WriteTypedArg(CodeWriter sb, ITypeSymbol? parameterType)
}
}

private static bool HasParam(ImmutableArray<IParameterSymbol> methodParameters, string name)
private static bool HasParam(in EquatableArray<MethodParam> methodParameters, string name)
{
foreach (var p in methodParameters)
{
Expand All @@ -179,6 +172,6 @@ private static bool HasParam(ImmutableArray<IParameterSymbol> methodParameters,
return false;
}

private static string Forward(ImmutableArray<IParameterSymbol> methodParameters, string name)
private static string Forward(in EquatableArray<MethodParam> methodParameters, string name)
=> HasParam(methodParameters, name) ? name : "default";
}
Loading
Loading