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

Add static modifier to members when possible, private and internal only (no public API change) #8534

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ private MembershipTableData Convert(List<SiloInstanceRecord> entries)
}
}

private MembershipEntry Parse(SiloInstanceRecord tableEntry)
private static MembershipEntry Parse(SiloInstanceRecord tableEntry)
{
var parse = new MembershipEntry
{
Expand Down
4 changes: 2 additions & 2 deletions src/AdoNet/Shared/Storage/OracleDatabaseCommandInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Data;
using System.Linq.Expressions;

Expand Down Expand Up @@ -59,7 +59,7 @@ private Action<IDbCommand> BuildSetBindByNameAction()
/// </summary>
/// <param name="enumName">String value of a OracleDbType enum value.</param>
/// <returns>An action which takes a OracleParameter as IDbDataParameter.</returns>
private Action<IDbDataParameter> BuildSetOracleDbTypeAction(string enumName)
private static Action<IDbDataParameter> BuildSetOracleDbTypeAction(string enumName)
{
var type = Type.GetType("Oracle.ManagedDataAccess.Client.OracleParameter, Oracle.ManagedDataAccess");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private async Task<QueueClient> GetCloudQueueClient(AzureQueueOptions options, I
}
}

private string SanitizeQueueName(string queueName)
private static string SanitizeQueueName(string queueName)
{
var tmp = queueName;
//Azure queue naming rules : https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-Queues-and-Metadata?redirectedfrom=MSDN
Expand All @@ -406,7 +406,7 @@ private string SanitizeQueueName(string queueName)
return tmp;
}

private void ValidateQueueName(string queueName)
private static void ValidateQueueName(string queueName)
{
// Naming Queues and Metadata: http://msdn.microsoft.com/en-us/library/windowsazure/dd179349.aspx
if (!(queueName.Length >= 3 && queueName.Length <= 63))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public bool TryReadEvents(int maxCount, out IEnumerable<EventData> events)
var eventData = EventHubBatchContainer.ToEventData(
this.serializer,
this.StreamId,
this.GenerateEvent(this.SequenceNumberCounter.Value),
GenerateEvent(this.SequenceNumberCounter.Value),
RequestContextExtensions.Export(this.deepCopier));

var wrapper = new WrappedEventData(
Expand All @@ -73,13 +73,13 @@ public bool TryReadEvents(int maxCount, out IEnumerable<EventData> events)
return eventDataList.Count > 0;
}

private IEnumerable<int> GenerateEvent(int sequenceNumber)
private static IEnumerable<int> GenerateEvent(int sequenceNumber)
{
var events = new List<int>();
events.Add(sequenceNumber);
return events;
}

public static Func<StreamId, IStreamDataGenerator<EventData>> CreateFactory(IServiceProvider services)
{
return (streamId) => ActivatorUtilities.CreateInstance<SimpleStreamEventDataGenerator>(services, streamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void ConfigureEventHubConnection(CreateConnectionDelegate createConnectio
CreateConnection = createConnection ?? throw new ArgumentNullException(nameof(createConnection));
}

private void ValidateValues(string eventHubName, string consumerGroup)
private static void ValidateValues(string eventHubName, string consumerGroup)
{
if (string.IsNullOrWhiteSpace(eventHubName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void SetState<T>(T state, JsonSerializerSettings jsonSettings)

private void SetStateInternal(string stringData)
{
this.CheckMaxDataSize((stringData ?? string.Empty).Length * 2, MAX_DATA_CHUNK_SIZE * MAX_DATA_CHUNKS_COUNT);
CheckMaxDataSize((stringData ?? string.Empty).Length * 2, MAX_DATA_CHUNK_SIZE * MAX_DATA_CHUNKS_COUNT);

foreach (var key in StringDataPropertyNames)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ private object GetPropertyOrDefault(string key)
return result;
}

private void CheckMaxDataSize(int dataSize, int maxDataSize)
private static void CheckMaxDataSize(int dataSize, int maxDataSize)
{
if (dataSize > maxDataSize)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static HashSet<BroadcastChannelSubscriber> FindImplicitSubscribers(strin
/// <param name="channelId">The channel ID to use for the grain ID construction.</param>
/// <param name="channelSubscriber">The GrainBindings for the grain to create</param>
/// <returns></returns>
private IBroadcastChannelConsumerExtension MakeConsumerReference(
private static IBroadcastChannelConsumerExtension MakeConsumerReference(
IGrainFactory grainFactory,
InternalChannelId channelId,
BroadcastChannelSubscriber channelSubscriber)
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.CodeGenerator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void ComputeAssembliesToExamine(IAssemblySymbol asm, HashSet<IAssemblySymbol> ex
}

// Returns descriptions of all data members (fields and properties)
private IEnumerable<IMemberDescription> GetDataMembers(FieldIdAssignmentHelper fieldIdAssignmentHelper)
private static IEnumerable<IMemberDescription> GetDataMembers(FieldIdAssignmentHelper fieldIdAssignmentHelper)
{
var members = new Dictionary<(uint, bool), IMemberDescription>();

Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.CodeGenerator/FieldIdAssignmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private bool ExtractFieldIdAnnotations()
return true;
}

private (string, uint) GetCanonicalNameAndFieldId(ITypeSymbol typeSymbol, string name)
private static (string, uint) GetCanonicalNameAndFieldId(ITypeSymbol typeSymbol, string name)
{
name = PropertyUtility.GetCanonicalName(name);

Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Core/Async/AsyncSerialExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Task AddNext(Func<Task> func)
return this.executor.AddNext(() => Wrap(func));
}

private async Task<bool> Wrap(Func<Task> func)
private static async Task<bool> Wrap(Func<Task> func)
{
await func();
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Core/Manifest/GrainBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private Cache GetCache()
}
}

private Cache BuildCache(ClusterManifest clusterManifest)
private static Cache BuildCache(ClusterManifest clusterManifest)
{
var result = new Dictionary<GrainType, GrainBindings>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void PostConfigure(string? name, EndpointOptions options)
}
}

private string? ReadNamespaceFromServiceAccount()
private static string? ReadNamespaceFromServiceAccount()
{
// Read the namespace from the pod's service account.
var serviceAccountNamespacePath = Path.Combine($"{Path.DirectorySeparatorChar}var", "run", "secrets", "kubernetes.io", "serviceaccount", "namespace");
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Runtime/Catalog/GrainTypeSharedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public GrainTypeSharedContext(
/// </summary>
public string? GrainTypeName { get; }

private TimeSpan GetCollectionAgeLimit(GrainType grainType, Type grainClass, GrainManifest siloManifest, GrainCollectionOptions collectionOptions)
private static TimeSpan GetCollectionAgeLimit(GrainType grainType, Type grainClass, GrainManifest siloManifest, GrainCollectionOptions collectionOptions)
{
if (siloManifest.Grains.TryGetValue(grainType, out var properties)
&& properties.Properties.TryGetValue(WellKnownGrainTypeProperties.IdleDeactivationPeriod, out var idleTimeoutString))
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Runtime/Core/ManagementGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private SiloAddress[] GetSiloAddresses(SiloAddress[] silos)
/// <param name="siloAddresses">List of silos to perform the action for</param>
/// <param name="perSiloAction">The action function to be performed for each silo</param>
/// <returns>Array containing one Task for each silo the action was performed for</returns>
private List<Task> PerformPerSiloAction(SiloAddress[] siloAddresses, Func<SiloAddress, Task> perSiloAction)
private static List<Task> PerformPerSiloAction(SiloAddress[] siloAddresses, Func<SiloAddress, Task> perSiloAction)
{
var requestsToSilos = new List<Task>();
foreach (SiloAddress siloAddress in siloAddresses)
Expand Down
4 changes: 2 additions & 2 deletions src/Orleans.Runtime/Hosting/SiloHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SiloHostedService(
IEnumerable<IConfigurationValidator> configurationValidators,
ILogger<SiloHostedService> logger)
{
this.ValidateSystemConfiguration(configurationValidators);
ValidateSystemConfiguration(configurationValidators);
this.silo = silo;
this.logger = logger;
}
Expand All @@ -36,7 +36,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
this.logger.LogInformation("Orleans Silo stopped.");
}

private void ValidateSystemConfiguration(IEnumerable<IConfigurationValidator> configurationValidators)
private static void ValidateSystemConfiguration(IEnumerable<IConfigurationValidator> configurationValidators)
{
foreach (var validator in configurationValidators)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ private async Task PeriodicallyRefreshMembershipTable()
}
}

private Task<bool> MembershipExecuteWithRetries(
private static Task<bool> MembershipExecuteWithRetries(
Func<int, Task<bool>> taskFunction,
TimeSpan timeout)
{
return MembershipExecuteWithRetries(taskFunction, timeout, (result, i) => result == false);
}

private Task<T> MembershipExecuteWithRetries<T>(
private static Task<T> MembershipExecuteWithRetries<T>(
Func<int, Task<T>> taskFunction,
TimeSpan timeout,
Func<T, int, bool> retryValueFilter)
Expand All @@ -303,8 +303,8 @@ private Task<T> MembershipExecuteWithRetries<T>(
taskFunction,
NUM_CONDITIONAL_WRITE_CONTENTION_ATTEMPTS,
NUM_CONDITIONAL_WRITE_ERROR_ATTEMPTS,
retryValueFilter, // if failed to Update on contention - retry
(exc, i) => true, // Retry on errors.
retryValueFilter, // if failed to Update on contention - retry
(exc, i) => true, // Retry on errors.
timeout,
new ExponentialBackoff(EXP_BACKOFF_CONTENTION_MIN, EXP_BACKOFF_CONTENTION_MAX, EXP_BACKOFF_STEP), // how long to wait between successful retries
new ExponentialBackoff(EXP_BACKOFF_ERROR_MIN, EXP_BACKOFF_ERROR_MAX, EXP_BACKOFF_STEP) // how long to wait between error retries
Expand Down
24 changes: 12 additions & 12 deletions src/Orleans.Serialization/Codecs/ArrayCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public T[] ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
$"Encountered too many elements in array of type {typeof(T[])} with declared length {length}.");

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(T[])}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
}

/// <summary>
Expand Down Expand Up @@ -266,12 +266,12 @@ public ReadOnlyMemory<T> ReadValue<TInput>(ref Reader<TInput> reader, Field fiel
return result;
}

private void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
$"Encountered too many elements in array of type {typeof(T[])} with declared length {length}.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(ReadOnlyMemory<T>)}, {length}, is greater than total length of input.");
}

Expand Down Expand Up @@ -428,12 +428,12 @@ public Memory<T> ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
$"Encountered too many elements in array of type {typeof(T[])} with declared length {length}.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(Memory<T>)}, {length}, is greater than total length of input.");
}

Expand Down Expand Up @@ -593,12 +593,12 @@ public ArraySegment<T> ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowIndexOutOfRangeException(int length) => throw new IndexOutOfRangeException(
$"Encountered too many elements in array of type {typeof(T[])} with declared length {length}.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(ArraySegment<T>)}, {length}, is greater than total length of input.");
}

Expand Down
4 changes: 2 additions & 2 deletions src/Orleans.Serialization/Codecs/CollectionCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public Collection<T> ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(Collection<T>)}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Orleans.Serialization/Codecs/DictionaryCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ public Dictionary<TKey, TValue> ReadValue<TInput>(ref Reader<TInput> reader, Fie
return result;
}

private Dictionary<TKey, TValue> CreateInstance(int length, IEqualityComparer<TKey> comparer, SerializerSession session, uint placeholderReferenceId)
private static Dictionary<TKey, TValue> CreateInstance(int length, IEqualityComparer<TKey> comparer, SerializerSession session, uint placeholderReferenceId)
{
var result = new Dictionary<TKey, TValue>(length, comparer);
ReferenceCodec.RecordObject(session, result, placeholderReferenceId);
return result;
}

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(Dictionary<TKey, TValue>)}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized dictionary is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized dictionary is missing its length field.");
}

/// <summary>
Expand Down Expand Up @@ -312,10 +312,10 @@ void IBaseCodec<Dictionary<TKey, TValue>>.Deserialize<TInput>(ref Reader<TInput>
}
}

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(Dictionary<TKey, TValue>)}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized dictionary is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized dictionary is missing its length field.");

}
}
6 changes: 3 additions & 3 deletions src/Orleans.Serialization/Codecs/HashSetCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ public HashSet<T> ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private HashSet<T> CreateInstance(int length, IEqualityComparer<T> comparer, SerializerSession session, uint placeholderReferenceId)
private static HashSet<T> CreateInstance(int length, IEqualityComparer<T> comparer, SerializerSession session, uint placeholderReferenceId)
{
var result = new HashSet<T>(length, comparer);
ReferenceCodec.RecordObject(session, result, placeholderReferenceId);
return result;
}

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(HashSet<T>)}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized set is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized set is missing its length field.");
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Orleans.Serialization/Codecs/ListCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public List<T> ReadValue<TInput>(ref Reader<TInput> reader, Field field)
return result;
}

private void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
private static void ThrowInvalidSizeException(int length) => throw new IndexOutOfRangeException(
$"Declared length of {typeof(List<T>)}, {length}, is greater than total length of input.");

private void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
private static void ThrowLengthFieldMissing() => throw new RequiredFieldMissingException("Serialized array is missing its length field.");
}

/// <summary>
Expand Down
Loading
Loading