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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" PrivateAssets="All" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[RequiresUnreferencedCode(
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code."),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
public class ObservableBackedBindingList<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : SortableBindingList<T>
{
private bool _addingNewInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
[RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code."),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
public class SortableBindingList<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : BindingList<T>
{
private bool _isSorted;
Expand All @@ -39,18 +39,16 @@ public SortableBindingList(List<T> list)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[RequiresUnreferencedCode("Requires accessing property 'Default' on the property descriptor's type")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
[UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2046",
Justification =
"This method is an override, and the base method isn't annotated with RequiresUnreferencedCode. "
+ "The entire type is marked with RequiresUnreferencedCode.")]
[SuppressMessage(
"AOT", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.",
Justification = "This method is an override, and the base method isn't annotated with RequiresDynamicCode. "
+ "The entire type is marked with RequiresDynamicCode.")]
[RequiresUnreferencedCode("Requires accessing property 'Default' on the property descriptor's type"),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type"), UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2046",
Justification =
"This method is an override, and the base method isn't annotated with RequiresUnreferencedCode. "
+ "The entire type is marked with RequiresUnreferencedCode."), SuppressMessage(
"AOT", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.",
Justification = "This method is an override, and the base method isn't annotated with RequiresDynamicCode. "
+ "The entire type is marked with RequiresDynamicCode.")]
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
{
if (PropertyComparer.CanSort(prop.PropertyType))
Expand Down Expand Up @@ -117,8 +115,8 @@ private sealed class PropertyComparer : Comparer<T>
private readonly ListSortDirection _direction;
private readonly PropertyDescriptor _prop;

[RequiresUnreferencedCode("Requires accessing property 'Default' on the property descriptor's type")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
[RequiresUnreferencedCode("Requires accessing property 'Default' on the property descriptor's type"),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
public PropertyComparer(PropertyDescriptor prop, ListSortDirection direction)
{
if (!prop.ComponentType.IsAssignableFrom(typeof(T)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@ bool IListSource.ContainsListCollection
/// An <see cref="IBindingList" /> in sync with the ObservableCollection.
/// </returns>
[RequiresUnreferencedCode(
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
[UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2046",
Justification =
"This method is an interface implementation, and the interface method isn't annotated with RequiresUnreferencedCode. "
+ "The entire type is marked with RequiresUnreferencedCode.")]
[SuppressMessage(
"AOT", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.",
Justification = "This method is an override, and the base method isn't annotated with RequiresDynamicCode. "
+ "The entire type is marked with RequiresDynamicCode.")]
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code."),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type"), UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2046",
Justification =
"This method is an interface implementation, and the interface method isn't annotated with RequiresUnreferencedCode. "
+ "The entire type is marked with RequiresUnreferencedCode."), SuppressMessage(
"AOT", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.",
Justification = "This method is an override, and the base method isn't annotated with RequiresDynamicCode. "
+ "The entire type is marked with RequiresDynamicCode.")]
IList IListSource.GetList()
=> _bindingList ??= this.ToBindingList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public class EntityTypeConfigurationAttribute : Attribute
/// Initializes a new instance of the <see cref="EntityTypeConfigurationAttribute" /> class.
/// </summary>
/// <param name="entityConfigurationType">The IEntityTypeConfiguration&lt;&gt; type to use.</param>
public EntityTypeConfigurationAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.Interfaces)] Type entityConfigurationType)
public EntityTypeConfigurationAttribute(
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.Interfaces)]
Type entityConfigurationType)
{
Check.NotNull(entityConfigurationType);

Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Abstractions/ObservableCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static class ObservableCollectionExtensions
/// <param name="source">The collection that the binding list will stay in sync with.</param>
/// <returns>The binding list.</returns>
[RequiresUnreferencedCode(
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
[RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
"BindingList raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code."),
RequiresDynamicCode("Requires calling MakeGenericType on the property descriptor's type")]
public static BindingList<T> ToBindingList<T>(this ObservableCollection<T> source)
where T : class
=> new ObservableBackedBindingList<T>(source);
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Analyzers/EFCore.Analyzers.nuspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
$CommonMetadataElements$
Expand All @@ -14,4 +15,4 @@
<file src="$OutputBinary$" target="analyzers\dotnet\cs\" />
<file src="$OutputSymbol$" target="analyzers\dotnet\cs\" />
</files>
</package>
</package>
12 changes: 6 additions & 6 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ private static readonly DiagnosticDescriptor Descriptor
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [Descriptor];
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> [Descriptor];

public override void Initialize(AnalysisContext context)
{
Expand Down Expand Up @@ -308,14 +309,13 @@ private static bool IsInternal(OperationAnalysisContext context, ITypeSymbol sym
&& (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol));

private static bool HasInternalAttribute(ISymbol symbol)
=> symbol.GetAttributes().Any(
a =>
a.AttributeClass!.ToDisplayString()
== "Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkInternalAttribute");
=> symbol.GetAttributes().Any(a =>
a.AttributeClass!.ToDisplayString()
== "Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkInternalAttribute");

private static bool IsInInternalNamespace(ISymbol symbol)
{
if (symbol?.ContainingNamespace?.ToDisplayString() is string ns)
if (symbol?.ContainingNamespace?.ToDisplayString() is { } ns)
{
var i = ns.IndexOf("EntityFrameworkCore", StringComparison.Ordinal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Microsoft.EntityFrameworkCore;

[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(InterpolatedStringUsageInRawQueriesCodeFixProvider))]
[Shared]
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(InterpolatedStringUsageInRawQueriesCodeFixProvider)), Shared]
public sealed class InterpolatedStringUsageInRawQueriesCodeFixProvider : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds => [EFDiagnostics.InterpolatedStringUsageInRawQueries];
public override ImmutableArray<string> FixableDiagnosticIds
=> [EFDiagnostics.InterpolatedStringUsageInRawQueries];

public override FixAllProvider GetFixAllProvider()
=> WellKnownFixAllProviders.BatchFixer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private static readonly DiagnosticDescriptor Descriptor
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [Descriptor];
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> [Descriptor];

public override void Initialize(AnalysisContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.ChangeTracking.Internal;
public sealed class StringDictionaryComparer<TDictionary, TElement> : ValueComparer<object>, IInfrastructure<ValueComparer>
{
private static readonly MethodInfo CompareMethod = typeof(StringDictionaryComparer<TDictionary, TElement>).GetMethod(
nameof(Compare), BindingFlags.Static | BindingFlags.NonPublic, [typeof(object), typeof(object), typeof(Func<TElement, TElement, bool>)])!;
nameof(Compare), BindingFlags.Static | BindingFlags.NonPublic,
[typeof(object), typeof(object), typeof(Func<TElement, TElement, bool>)])!;

private static readonly MethodInfo GetHashCodeMethod = typeof(StringDictionaryComparer<TDictionary, TElement>).GetMethod(
nameof(GetHashCode), BindingFlags.Static | BindingFlags.NonPublic, [typeof(IEnumerable), typeof(Func<TElement, int>)])!;
Expand Down Expand Up @@ -72,7 +73,7 @@ private static Expression<Func<object, int>> GetHashCodeLambda(ValueComparer ele
Expression.Convert(
prm,
typeof(IEnumerable)),
elementComparer.HashCodeExpression),
elementComparer.HashCodeExpression),
prm);
}

Expand Down
25 changes: 12 additions & 13 deletions src/EFCore.Cosmos/Diagnostics/Internal/CosmosLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,18 @@ private static string ExecutedReadNext(EventDefinitionBase definition, EventData
{
var d = (FallbackEventDefinition)definition;
var p = (CosmosQueryExecutedEventData)payload;
return d.GenerateMessage(
l => l.Log(
d.Level,
d.EventId,
d.MessageFormat,
p.Elapsed.TotalMilliseconds,
p.RequestCharge,
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.PartitionKeyValue.ToString() : "?",
FormatParameters(p.Parameters, p is { LogSensitiveData: true, Parameters.Count: > 0 }),
Environment.NewLine,
p.QuerySql));
return d.GenerateMessage(l => l.Log(
d.Level,
d.EventId,
d.MessageFormat,
p.Elapsed.TotalMilliseconds,
p.RequestCharge,
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.PartitionKeyValue.ToString() : "?",
FormatParameters(p.Parameters, p is { LogSensitiveData: true, Parameters.Count: > 0 }),
Environment.NewLine,
p.QuerySql));
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Extensions/CosmosDbFunctionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static double Rrf(this DbFunctions _, params double[] scores)
/// <param name="vector2">The second vector.</param>
/// <param name="useBruteForce">
/// An optional boolean specifying how the computed value is used in an <c>ORDER BY</c> expression.
/// If <see langword="true"/>, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// If <see langword="true" />, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// property, if it exists. Default value is <see langword="false" />.
/// </param>
/// <param name="options">An optional object used to specify options for the vector distance calculation.</param>
Expand All @@ -129,7 +129,7 @@ public static double VectorDistance(
/// <param name="vector2">The second vector.</param>
/// <param name="useBruteForce">
/// An optional boolean specifying how the computed value is used in an <c>ORDER BY</c> expression.
/// If <see langword="true"/>, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// If <see langword="true" />, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// property, if it exists. Default value is <see langword="false" />.
/// </param>
/// <param name="options">An optional object used to specify options for the vector distance calculation.</param>
Expand All @@ -149,7 +149,7 @@ public static double VectorDistance(
/// <param name="vector2">The second vector.</param>
/// <param name="useBruteForce">
/// An optional boolean specifying how the computed value is used in an <c>ORDER BY</c> expression.
/// If <see langword="true"/>, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// If <see langword="true" />, then brute force is used. A value of <see langword="false" /> uses any index defined on the vector
/// property, if it exists. Default value is <see langword="false" />.
/// </param>
/// <param name="options">An optional object used to specify options for the vector distance calculation.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,11 @@ public static bool CanSetThroughput(
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-triggers">Database triggers</see> for more information and examples.
/// </remarks>
public static TriggerBuilder HasTrigger(this EntityTypeBuilder entityTypeBuilder, string modelName, TriggerType triggerType, TriggerOperation triggerOperation)
public static TriggerBuilder HasTrigger(
this EntityTypeBuilder entityTypeBuilder,
string modelName,
TriggerType triggerType,
TriggerOperation triggerOperation)
{
var triggerBuilder = EntityTypeBuilder.HasTrigger(entityTypeBuilder.Metadata, modelName);
triggerBuilder.Metadata.SetTriggerType(triggerType);
Expand All @@ -1039,7 +1043,11 @@ public static TriggerBuilder HasTrigger(this EntityTypeBuilder entityTypeBuilder
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-triggers">Database triggers</see> for more information and examples.
/// </remarks>
public static TriggerBuilder HasTrigger<TEntity>(this EntityTypeBuilder<TEntity> entityTypeBuilder, string modelName, TriggerType triggerType, TriggerOperation triggerOperation)
public static TriggerBuilder HasTrigger<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
string modelName,
TriggerType triggerType,
TriggerOperation triggerOperation)
where TEntity : class
{
var triggerBuilder = EntityTypeBuilder.HasTrigger(entityTypeBuilder.Metadata, modelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void SetContainer(this IMutableEntityType entityType, string? name
}

private static string? GetDefaultContainingPropertyName(IReadOnlyEntityType entityType)
=> entityType.FindOwnership() is IReadOnlyForeignKey ownership
=> entityType.FindOwnership() is { } ownership
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok with the change, but doesn't having an explicit type help with readability and debugging? Applies to here and other places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks strange at first, but as you get used to it it's actually more readable as you immediately know that it's just a null check and it's not trying to cast to a different type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the other PR, I'm slightly on the fence (can see both sides). On the one hand clearly making something as a null check is valuable (as @AndriySvyryd says), on the other hand simply having the .NET type explicitly is also valuable in at least some situations. It's a bit like how sometimes it's better to avoid var in order to make it very clear what type is being used.

But am OK with it either way.

? ownership.PrincipalToDependent!.Name
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public static bool CanSetVectorIndexType(

/// <summary>
/// Configures the index as a full-text index.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see> for more information.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see>
/// for more information.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
Expand All @@ -121,7 +122,8 @@ public static IndexBuilder IsFullTextIndex(this IndexBuilder indexBuilder, bool

/// <summary>
/// Configures the index as a full-text index.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see> for more information.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see>
/// for more information.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
Expand All @@ -137,7 +139,8 @@ public static IndexBuilder<TEntity> IsFullTextIndex<TEntity>(

/// <summary>
/// Configures the index as a full-text index.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see> for more information.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see>
/// for more information.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
Expand Down
Loading
Loading