Skip to content

share-argument-exception-extension #8098

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c245e04
share if null or empty
Zombach Mar 16, 2025
b6a7c8f
fix mt by feedback(static method, add tests)
Zombach Mar 18, 2025
b5621cb
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 18, 2025
ea670e6
fix mr conflict
Zombach Mar 19, 2025
24f864a
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 19, 2025
58ef279
remove not use using
Zombach Mar 19, 2025
f04a325
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 19, 2025
172499d
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 19, 2025
0e9dce0
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 19, 2025
c21eee6
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 20, 2025
0fa7859
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 20, 2025
f870d0a
fix mr conflict
Zombach Mar 21, 2025
12df020
fix mr conflict
Zombach Mar 21, 2025
1cd0fc4
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 21, 2025
b4fe5f9
fix conflicts mr
Zombach Mar 22, 2025
33a3873
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 23, 2025
01b60b1
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 23, 2025
a977e29
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 24, 2025
8ec6449
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 24, 2025
5af93f1
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 25, 2025
d823e77
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 25, 2025
33bb74d
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 26, 2025
c5ada8d
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Mar 27, 2025
7e4ddf1
fix mr
Zombach Apr 19, 2025
67a2bc8
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 21, 2025
5951601
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 22, 2025
8fbbeec
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 25, 2025
6e4fc83
fix failed test
Zombach Apr 26, 2025
148c580
remove "Do not call ConfigureAwait(false) in test method" Causes an …
Zombach Apr 26, 2025
5b7db56
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 27, 2025
f03b8f7
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 28, 2025
5967871
fix mr conflict
Zombach Apr 29, 2025
5f34d1d
up to main
Zombach Apr 29, 2025
3ca50cc
add XunitCultureAttribute
Zombach Apr 29, 2025
339042b
Revert "add XunitCultureAttribute"
Zombach Apr 29, 2025
516b5bb
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach Apr 29, 2025
507b29a
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach May 1, 2025
e7a9251
Merge branch 'dotnet:main' into common/share-argument-exception-exten…
Zombach May 1, 2025
d0deb1a
up to main
Zombach May 9, 2025
c8c906e
Merge remote-tracking branch 'origin/main' into common/share-argument…
Zombach May 11, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)src\Shared\AzureRoleAssignmentUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this in each project file, I suggest considering a different approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put the shared file in the Shared folder (like the line above)?

</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
Expand All @@ -25,17 +22,17 @@ public class AzureOpenAIDeployment(string name, string modelName, string modelVe
/// <summary>
/// Gets the name of the deployment.
/// </summary>
public string Name { get; private set; } = ThrowIfNullOrEmpty(name);
public string Name { get; private set; } = name.ThrowIfNullOrEmpty();

/// <summary>
/// Gets the name of the model.
/// </summary>
public string ModelName { get; private set; } = ThrowIfNullOrEmpty(modelName);
public string ModelName { get; private set; } = modelName.ThrowIfNullOrEmpty();

/// <summary>
/// Gets the version of the model.
/// </summary>
public string ModelVersion { get; private set; } = ThrowIfNullOrEmpty(modelVersion);
public string ModelVersion { get; private set; } = modelVersion.ThrowIfNullOrEmpty();

/// <summary>
/// Gets the name of the SKU.
Expand All @@ -52,10 +49,4 @@ public class AzureOpenAIDeployment(string name, string modelName, string modelVe
/// The default value is <inheritdoc cref="DefaultSkuCapacity"/>.
/// </value>
public int SkuCapacity { get; set; } = skuCapacity ?? DefaultSkuCapacity;

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="..\Shared\Cosmos\CosmosConstants.cs" Link="Shared\CosmosConstants.cs" />
<Compile Include="..\Shared\Cosmos\CosmosUtils.cs" Link="Shared\CosmosUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 14 additions & 10 deletions src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBContainerResource.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Azure;
Expand All @@ -17,15 +15,27 @@ namespace Aspire.Hosting.Azure;
public class AzureCosmosDBContainerResource(string name, string containerName, string partitionKeyPath, AzureCosmosDBDatabaseResource parent)
: Resource(name), IResourceWithParent<AzureCosmosDBDatabaseResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _containerName = containerName.ThrowIfNullOrEmpty();

/// <summary>
/// Gets or sets the container name.
/// </summary>
public string ContainerName { get; set; } = ThrowIfNullOrEmpty(containerName);
public string ContainerName
{
get => _containerName;
set => _containerName = value.ThrowIfNullOrEmpty(nameof(containerName));
}

private string _partitionKeyPath = partitionKeyPath.ThrowIfNullOrEmpty();

/// <summary>
/// Gets or sets the partition key path.
/// </summary>
public string PartitionKeyPath { get; set; } = ThrowIfNullOrEmpty(partitionKeyPath);
public string PartitionKeyPath
{
get => _partitionKeyPath;
set => _partitionKeyPath = value.ThrowIfNullOrEmpty(nameof(partitionKeyPath));
}

/// <summary>
/// Gets the parent Azure Cosmos DB database resource.
Expand All @@ -40,10 +50,4 @@ public class AzureCosmosDBContainerResource(string name, string containerName, s
// ensure Azure Functions projects can WithReference a CosmosDB database container
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName) =>
((IResourceWithAzureFunctionsConfig)Parent).ApplyAzureFunctionsConfiguration(target, connectionName);

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Azure;
Expand All @@ -17,10 +15,16 @@ namespace Aspire.Hosting.Azure;
public class AzureCosmosDBDatabaseResource(string name, string databaseName, AzureCosmosDBResource parent)
: Resource(name), IResourceWithParent<AzureCosmosDBResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _databaseName = databaseName.ThrowIfNullOrEmpty();

/// <summary>
/// Gets or sets the database name.
/// </summary>
public string DatabaseName { get; set; } = ThrowIfNullOrEmpty(databaseName);
public string DatabaseName
{
get => _databaseName;
set => _databaseName = value.ThrowIfNullOrEmpty(nameof(databaseName));
}

/// <summary>
/// The containers for this database.
Expand All @@ -40,10 +44,4 @@ public class AzureCosmosDBDatabaseResource(string name, string databaseName, Azu
// ensure Azure Functions projects can WithReference a CosmosDB database
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName) =>
((IResourceWithAzureFunctionsConfig)Parent).ApplyAzureFunctionsConfiguration(target, connectionName);

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)src\Shared\AzureRoleAssignmentUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Aspire.Hosting.ApplicationModel;
using Azure.Provisioning;
Expand All @@ -19,10 +17,16 @@ namespace Aspire.Hosting.Azure;
public class AzureEventHubConsumerGroupResource(string name, string consumerGroupName, AzureEventHubResource parent)
: Resource(name), IResourceWithParent<AzureEventHubResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _consumerGroupName = consumerGroupName.ThrowIfNullOrEmpty();

/// <summary>
/// The event hub consumer group name.
/// </summary>
public string ConsumerGroupName { get; set; } = ThrowIfNullOrEmpty(consumerGroupName);
public string ConsumerGroupName
{
get => _consumerGroupName;
set => _consumerGroupName = value.ThrowIfNullOrEmpty(nameof(consumerGroupName));
}

/// <summary>
/// Gets the parent Azure Event Hub resource.
Expand Down Expand Up @@ -60,10 +64,4 @@ internal void WriteJsonObjectProperties(Utf8JsonWriter writer)
{
writer.WriteString(nameof(Name), ConsumerGroupName);
}

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
16 changes: 7 additions & 9 deletions src/Aspire.Hosting.Azure.EventHubs/AzureEventHubResource.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Aspire.Hosting.ApplicationModel;
using Azure.Provisioning;
Expand All @@ -19,10 +17,16 @@ namespace Aspire.Hosting.Azure;
public class AzureEventHubResource(string name, string hubName, AzureEventHubsResource parent)
: Resource(name), IResourceWithParent<AzureEventHubsResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _hubName = hubName.ThrowIfNullOrEmpty();

/// <summary>
/// The event hub name.
/// </summary>
public string HubName { get; set; } = ThrowIfNullOrEmpty(hubName);
public string HubName
{
get => _hubName;
set => _hubName = value.ThrowIfNullOrEmpty(nameof(hubName));
}

/// <summary>
/// Number of partitions created for the Event Hub, allowed values are from
Expand Down Expand Up @@ -109,10 +113,4 @@ internal void WriteJsonObjectProperties(Utf8JsonWriter writer)
writer.WriteEndArray();
}
#pragma warning restore CA1507 // Use nameof to express symbol names

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="$(SharedDir)StringComparers.cs" Link="Utils\StringComparers.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Azure;
Expand All @@ -29,7 +27,7 @@ public class AzurePostgresFlexibleServerDatabaseResource(string name, string dat
/// <summary>
/// Gets the database name.
/// </summary>
public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);
public string DatabaseName { get; } = databaseName.ThrowIfNullOrEmpty();

/// <summary>
/// Gets the inner PostgresDatabaseResource resource.
Expand All @@ -41,12 +39,6 @@ public class AzurePostgresFlexibleServerDatabaseResource(string name, string dat
/// <inheritdoc />
public override ResourceAnnotationCollection Annotations => InnerResource?.Annotations ?? base.Annotations;

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}

internal void SetInnerResource(PostgresDatabaseResource innerResource)
{
// Copy the annotations to the inner resource before making it the inner resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)src\Aspire.Hosting\Utils\PasswordGenerator.cs" Link="Utils\PasswordGenerator.cs" />
<Compile Include="$(RepoRoot)src\Shared\AzureRoleAssignmentUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Xml;
using Aspire.Hosting.ApplicationModel;
Expand All @@ -20,15 +18,15 @@ namespace Aspire.Hosting.Azure;
public class AzureServiceBusQueueResource(string name, string queueName, AzureServiceBusResource parent)
: Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _queueName = ThrowIfNullOrEmpty(queueName);
private string _queueName = queueName.ThrowIfNullOrEmpty();

/// <summary>
/// The queue name.
/// </summary>
public string QueueName
{
get => _queueName;
set => _queueName = ThrowIfNullOrEmpty(value, nameof(queueName));
set => _queueName = value.ThrowIfNullOrEmpty(nameof(queueName));
}

/// <summary>
Expand Down Expand Up @@ -198,10 +196,4 @@ internal void WriteJsonObjectProperties(Utf8JsonWriter writer)
}
writer.WriteEndObject();
}

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
12 changes: 2 additions & 10 deletions src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusRule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Azure.Provisioning;

Expand All @@ -17,15 +15,15 @@ namespace Aspire.Hosting.Azure;
/// </remarks>
public class AzureServiceBusRule(string name)
{
private string _name = ThrowIfNullOrEmpty(name);
private string _name = name.ThrowIfNullOrEmpty();

/// <summary>
/// The rule name.
/// </summary>
public string Name
{
get => _name;
set => _name = ThrowIfNullOrEmpty(value, nameof(name));
set => _name = value.ThrowIfNullOrEmpty(nameof(name));
}

/// <summary>
Expand Down Expand Up @@ -181,10 +179,4 @@ internal void WriteJsonObjectProperties(Utf8JsonWriter writer)

writer.WriteEndObject(); // Properties
}

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Xml;
using Aspire.Hosting.ApplicationModel;
Expand All @@ -20,15 +18,15 @@ namespace Aspire.Hosting.Azure;
public class AzureServiceBusSubscriptionResource(string name, string subscriptionName, AzureServiceBusTopicResource parent)
: Resource(name), IResourceWithParent<AzureServiceBusTopicResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _subscriptionName = ThrowIfNullOrEmpty(subscriptionName);
private string _subscriptionName = subscriptionName.ThrowIfNullOrEmpty();

/// <summary>
/// The subscription name.
/// </summary>
public string SubscriptionName
{
get => _subscriptionName;
set => _subscriptionName = ThrowIfNullOrEmpty(value, nameof(subscriptionName));
set => _subscriptionName = value.ThrowIfNullOrEmpty(nameof(subscriptionName));
}

/// <summary>
Expand Down Expand Up @@ -183,10 +181,4 @@ internal void WriteJsonObjectProperties(Utf8JsonWriter writer)

writer.WriteEndObject();
}

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Loading
Loading