Skip to content

Use primary constructors and expression-bodied members in more places#9854

Open
KhanbalaRashidov wants to merge 1 commit intodotnet:mainfrom
KhanbalaRashidov:main
Open

Use primary constructors and expression-bodied members in more places#9854
KhanbalaRashidov wants to merge 1 commit intodotnet:mainfrom
KhanbalaRashidov:main

Conversation

@KhanbalaRashidov
Copy link
Copy Markdown

@KhanbalaRashidov KhanbalaRashidov commented Dec 24, 2025

Changes

  • Converted traditional constructors to primary constructors
  • Replaced single-line method bodies with expression-bodied members
  • No functional changes - purely syntactic modernization
Microsoft Reviewers: Open in CodeFlow

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Syntactic modernization across Orleans.Core to adopt newer C# features (primary constructors and expression-bodied members) while preserving existing runtime behavior.

Changes:

  • Replaced a number of traditional constructors with primary constructors.
  • Converted eligible single-statement constructors/methods to expression-bodied members.
  • Collapsed some private readonly fields into primary-constructor parameter captures and property initializers.

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Orleans.Core/Timers/CoarseStopwatch.cs Simplifies private ctor to expression-bodied assignment.
src/Orleans.Core/Threading/RecursiveInterlockedExchangeLock.cs Simplifies ctor initialization to expression-bodied form.
src/Orleans.Core/Serialization/OrleansJsonSerializerOptions.cs Simplifies options initialization; uses primary ctor for configurator.
src/Orleans.Core/Serialization/OrleansJsonSerializer.cs Converts to primary ctor and field initializer for settings.
src/Orleans.Core/Serialization/OrleansJsonSerializationBinder.cs Converts to primary ctor and removes redundant field.
src/Orleans.Core/Runtime/MembershipTableSnapshot.cs Converts to primary ctor and initializes get-only properties from parameters.
src/Orleans.Core/Runtime/ClientGrainContext.cs Converts to primary ctor and inlines runtime client usage.
src/Orleans.Core/Runtime/CallbackData.cs Converts to primary ctor; moves stopwatch/message initialization to initializers.
src/Orleans.Core/Providers/ProviderStateManager.cs Simplifies default state initialization to expression-bodied ctor.
src/Orleans.Core/Providers/ClientProviderRuntime.cs Converts to primary ctor and uses property initializer for ServiceProvider.
src/Orleans.Core/Networking/Shared/TransportConnection.cs Simplifies ctor to expression-bodied FastReset call.
src/Orleans.Core/Networking/Shared/SocketsTrace.cs Converts to primary ctor and uses captured logger.
src/Orleans.Core/Networking/Shared/SocketAwaitableEventArgs.cs Converts to primary ctor and uses captured PipeScheduler.
src/Orleans.Core/Networking/Shared/DuplexPipe.cs Converts to primary ctor and property initializers.
src/Orleans.Core/Networking/NetworkingTrace.cs Converts to primary ctor and inline logger creation.
src/Orleans.Core/Networking/ConnectionPreamble.cs Converts helper to primary ctor and removes redundant serializer field.
src/Orleans.Core/Networking/ConnectionManagerLifecycleAdapter.cs Converts to primary ctor and uses captured ConnectionManager.
src/Orleans.Core/Networking/ConnectionLogScope.cs Converts to primary ctor and removes redundant connection field.
src/Orleans.Core/Networking/ConnectionFactory.cs Converts to primary ctor and property initializer for ConnectionOptions.
src/Orleans.Core/Networking/ClientOutboundConnectionFactory.cs Converts to primary ctor; stores options values in readonly fields.
src/Orleans.Core/Networking/ClientOutboundConnection.cs Converts to primary ctor and property initializer for RemoteSiloAddress.
src/Orleans.Core/Messaging/StaticGatewayListProvider.cs Converts to primary ctor; stores resolved options values in fields.
src/Orleans.Core/Messaging/CachingSiloAddressCodec.cs Simplifies ctor initialization to expression-bodied form.
src/Orleans.Core/Messaging/CachingIdSpanCodec.cs Simplifies ctor initialization to expression-bodied form.
src/Orleans.Core/Manifest/ImplementedInterfaceProvider.cs Converts to primary ctor and removes redundant resolver field.
src/Orleans.Core/Manifest/IClusterManifestSystemTarget.cs Converts manifest update DTO to primary ctor + property initializers.
src/Orleans.Core/Manifest/GrainVersionManifest.cs Converts to primary ctor; moves cache/local version init to field initializers.
src/Orleans.Core/Manifest/GrainTypeResolver.cs Converts to primary ctor and uses captured argument formatter.
src/Orleans.Core/Manifest/GrainPropertiesResolver.cs Converts to primary ctor and removes redundant provider field.
src/Orleans.Core/Manifest/GrainInterfaceTypeResolver.cs Converts to primary ctor and uses captured type converter.
src/Orleans.Core/Manifest/GrainBindings.cs Converts to primary ctor and initializes get-only properties from parameters.
src/Orleans.Core/Lifecycle/MigrationContext.cs Simplifies ctor to expression-bodied assignment.
src/Orleans.Core/GrainReferences/GrainReferenceActivator.cs Converts to primary ctor and field initializers for deps.
src/Orleans.Core/Diagnostics/Metrics/Aggregators/HistogramBucketAggregator.cs Converts to primary ctor and inlines tags/bound initialization.
src/Orleans.Core/Diagnostics/Metrics/Aggregators/CounterAggregator.cs Simplifies default ctor to expression-bodied assignment.
src/Orleans.Core/Diagnostics/Metrics/Aggregators/AggregatorKey.cs Converts to primary ctor and initializes get-only properties from parameters.
src/Orleans.Core/Diagnostics/MessagingTrace.cs Simplifies ctor to expression-bodied logger initialization.
src/Orleans.Core/Core/GrainMethodInvoker.cs Converts to primary ctor and removes redundant backing fields.
src/Orleans.Core/Core/GrainInterfaceTypeToGrainTypeResolver.cs Simplifies ctor to expression-bodied assignment.
src/Orleans.Core/Core/GrainFactory.cs Converts to primary ctor and removes redundant backing fields.

Comment on lines +19 to +20
private readonly StaticGatewayListProviderOptions options = options.Value;
private readonly TimeSpan maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The field name options shadows the primary-constructor parameter options, making options = options.Value harder to read/maintain. Consider renaming the field (for example to _options/providerOptions) to avoid shadowing and clarify the distinction between IOptions<T> and the resolved options value.

See below for a potential fix:

        private readonly StaticGatewayListProviderOptions providerOptions = options.Value;
        private readonly TimeSpan maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;

        /// <inheritdoc />
        public Task InitializeGatewayListProvider() => Task.CompletedTask;
        
        /// <inheritdoc />
        public Task<IList<Uri>> GetGateways() => Task.FromResult<IList<Uri>>(this.providerOptions.Gateways);

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +20
private readonly ClientConnectionOptions clientConnectionOptions = clientConnectionOptions.Value;
private readonly ClusterOptions clusterOptions = clusterOptions.Value;
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

These fields (clientConnectionOptions/clusterOptions) use the same identifier as the primary-constructor parameters but with different types (ClientConnectionOptions vs IOptions<ClientConnectionOptions>). Even though it compiles, it’s easy to misread and can lead to mistakes during future edits. Consider renaming the fields (for example _clientConnectionOptions/_clusterOptions) or using distinct parameter names to avoid shadowing/confusion.

Copilot uses AI. Check for mistakes.
@ReubenBond ReubenBond changed the title refactor: modernize syntax with primary constructors and expression-bodied members Use primary constructors and expression-bodied members in more places Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants