Skip to content

Commit 465a111

Browse files
authored
Fixes in code style and comments (#5)
***NO_CI***
1 parent 3b54a7c commit 465a111

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+302
-184
lines changed

nanoFramework.DependencyInjection/DependencyInjection/ActivatorUtilities.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
35

46
using System;
57
using System.Reflection;
@@ -15,9 +17,9 @@ public static class ActivatorUtilities
1517
/// Instantiate a type with constructor arguments provided directly and/or from an <see cref="IServiceProvider"/>.
1618
/// </summary>
1719
/// <param name="provider">The service provider used to resolve dependencies.</param>
18-
/// <param name="instanceType">The type to activate</param>
20+
/// <param name="instanceType">The type to activate.</param>
1921
/// <param name="parameters">Constructor arguments not provided by the <paramref name="provider"/>.</param>
20-
/// <returns>An activated object of type instanceType.</returns>
22+
/// <returns>An activated object of type <paramref name="instanceType"/>.</returns>
2123
/// <exception cref="InvalidOperationException">A suitable constructor for type <paramref name="instanceType"/> could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.</exception>
2224
public static object CreateInstance(IServiceProvider provider, Type instanceType, params object[] parameters)
2325
{
@@ -51,10 +53,10 @@ public static object CreateInstance(IServiceProvider provider, Type instanceType
5153
/// <summary>
5254
/// Retrieve an instance of the given type from the service provider. If one is not found then instantiate it directly.
5355
/// </summary>
54-
/// <param name="provider">The service provider<./param>
56+
/// <param name="provider">The service provider.</param>
5557
/// <param name="type">The type of the service.</param>
5658
/// <returns>The resolved service or created instance.</returns>
57-
/// /// <exception cref="InvalidOperationException">Unable to resolve a service while attempting to activatea constructor.</exception>
59+
/// /// <exception cref="InvalidOperationException">Unable to resolve a service while attempting to activate a constructor.</exception>
5860
public static object GetServiceOrCreateInstance(IServiceProvider provider, Type type)
5961
{
6062
return provider.GetService(type) ?? CreateInstance(provider, type);
@@ -77,21 +79,24 @@ public int Match(object[] givenParameters)
7779
{
7880
int applyIndexStart = 0;
7981
int applyExactLength = 0;
82+
8083
for (int givenIndex = 0; givenIndex != givenParameters.Length; givenIndex++)
8184
{
8285
Type givenType = givenParameters[givenIndex].GetType();
8386
bool givenMatched = false;
8487

8588
for (int applyIndex = applyIndexStart; givenMatched == false && applyIndex != _parameters.Length; ++applyIndex)
8689
{
87-
if (_parameterValues[applyIndex] == null &&
88-
_parameters[applyIndex].ParameterType.Equals(givenType)) //TODO: Type.IsAssignableFrom?
90+
if (_parameterValues[applyIndex] == null
91+
&& _parameters[applyIndex].ParameterType.Equals(givenType)) //TODO: Type.IsAssignableFrom?
8992
{
9093
givenMatched = true;
9194
_parameterValues[applyIndex] = givenParameters[givenIndex];
95+
9296
if (applyIndexStart == applyIndex)
9397
{
9498
applyIndexStart++;
99+
95100
if (applyIndex == givenIndex)
96101
{
97102
applyExactLength = applyIndex;
@@ -115,6 +120,7 @@ public object CreateInstance(IServiceProvider provider)
115120
if (_parameterValues[index] == null)
116121
{
117122
object value = provider.GetService(_parameters[index].ParameterType);
123+
118124
if (value == null)
119125
{
120126
throw new InvalidOperationException($"'{_parameters[index].ParameterType}'->'{_constructor.DeclaringType}'.");
@@ -130,4 +136,4 @@ public object CreateInstance(IServiceProvider provider)
130136
}
131137
}
132138
}
133-
}
139+
}

nanoFramework.DependencyInjection/DependencyInjection/IServiceCollection.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
35

46
using System.Collections;
57

@@ -80,4 +82,4 @@ public interface IServiceCollection
8082
/// <param name="index">The zero-based index of the item to remove.</param>
8183
void RemoveAt(int index);
8284
}
83-
}
85+
}

nanoFramework.DependencyInjection/DependencyInjection/ServiceCollection.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
35

46
using System.Collections;
57

@@ -14,10 +16,10 @@ public class ServiceCollection : IServiceCollection
1416
private static readonly object _syncLock = new object();
1517
private readonly ArrayList _descriptors = new ArrayList();
1618

17-
/// <inheritdoc />
19+
/// <inheritdoc/>
1820
public bool IsReadOnly => false;
1921

20-
/// <inheritdoc />
22+
/// <inheritdoc/>
2123
public int Count
2224
{
2325
get
@@ -29,7 +31,7 @@ public int Count
2931
}
3032
}
3133

32-
/// <inheritdoc />
34+
/// <inheritdoc/>
3335
public ServiceDescriptor this[int index]
3436
{
3537
get
@@ -49,7 +51,7 @@ public ServiceDescriptor this[int index]
4951
}
5052
}
5153

52-
/// <inheritdoc />
54+
/// <inheritdoc/>
5355
public int Add(ServiceDescriptor item)
5456
{
5557
lock (_syncLock)
@@ -58,7 +60,7 @@ public int Add(ServiceDescriptor item)
5860
}
5961
}
6062

61-
/// <inheritdoc />
63+
/// <inheritdoc/>
6264
public void Clear()
6365
{
6466
lock (_syncLock)
@@ -67,7 +69,7 @@ public void Clear()
6769
}
6870
}
6971

70-
/// <inheritdoc />
72+
/// <inheritdoc/>
7173
public bool Contains(ServiceDescriptor item)
7274
{
7375
lock (_syncLock)
@@ -76,7 +78,7 @@ public bool Contains(ServiceDescriptor item)
7678
}
7779
}
7880

79-
/// <inheritdoc />
81+
/// <inheritdoc/>
8082
public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
8183
{
8284
lock (_syncLock)
@@ -85,7 +87,7 @@ public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
8587
}
8688
}
8789

88-
/// <inheritdoc />
90+
/// <inheritdoc/>
8991
public void Remove(ServiceDescriptor item)
9092
{
9193
lock (_syncLock)
@@ -94,7 +96,7 @@ public void Remove(ServiceDescriptor item)
9496
}
9597
}
9698

97-
/// <inheritdoc />
99+
/// <inheritdoc/>
98100
public IEnumerator GetEnumerator()
99101
{
100102
lock (_syncLock)
@@ -103,7 +105,7 @@ public IEnumerator GetEnumerator()
103105
}
104106
}
105107

106-
/// <inheritdoc />
108+
/// <inheritdoc/>
107109
public int IndexOf(ServiceDescriptor item)
108110
{
109111
lock (_syncLock)
@@ -112,7 +114,7 @@ public int IndexOf(ServiceDescriptor item)
112114
}
113115
}
114116

115-
/// <inheritdoc />
117+
/// <inheritdoc/>
116118
public void Insert(int index, ServiceDescriptor item)
117119
{
118120
lock (_syncLock)
@@ -121,7 +123,7 @@ public void Insert(int index, ServiceDescriptor item)
121123
}
122124
}
123125

124-
/// <inheritdoc />
126+
/// <inheritdoc/>
125127
public void RemoveAt(int index)
126128
{
127129
lock (_syncLock)

nanoFramework.DependencyInjection/DependencyInjection/ServiceCollectionContainerBuilderExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
35

46
using System;
57

nanoFramework.DependencyInjection/DependencyInjection/ServiceCollectionServiceExtensions.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
35

46
using System;
57
using System.Collections;
68

79
namespace nanoFramework.DependencyInjection
810
{
11+
/// <summary>
12+
/// Extensions for <see cref="ServiceCollection"/>.
13+
/// </summary>
914
public static class ServiceCollectionServiceExtensions
1015
{
1116
/// <summary>
@@ -18,7 +23,7 @@ public static class ServiceCollectionServiceExtensions
1823
/// <param name="implementationType">The implementation type of the service.</param>
1924
/// <returns>A reference to this instance after the operation has completed.</returns>
2025
/// <seealso cref="ServiceLifetime.Singleton"/>
21-
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be nul.</exception>
26+
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be <see langword="null"/>.</exception>
2227
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
2328
{
2429
if (services == null)
@@ -40,7 +45,7 @@ public static IServiceCollection AddSingleton(this IServiceCollection services,
4045
/// <param name="serviceType">The type of the service to register and the implementation to use.</param>
4146
/// <returns>A reference to this instance after the operation has completed.</returns>
4247
/// <seealso cref="ServiceLifetime.Singleton"/>
43-
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be null.</exception>
48+
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be <see langword="null"/>.</exception>
4449
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType)
4550
{
4651
if (services == null)
@@ -61,7 +66,7 @@ public static IServiceCollection AddSingleton(this IServiceCollection services,
6166
/// <param name="implementationInstance">The instance of the service.</param>
6267
/// <returns>A reference to this instance after the operation has completed.</returns>
6368
/// <seealso cref="ServiceLifetime.Singleton"/>
64-
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be null.</exception>
69+
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be <see langword="null"/>.</exception>
6570
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, object implementationInstance)
6671
{
6772
if (services == null)
@@ -71,6 +76,7 @@ public static IServiceCollection AddSingleton(this IServiceCollection services,
7176

7277
var serviceDescriptor = new ServiceDescriptor(serviceType, implementationInstance);
7378
services.Add(serviceDescriptor);
79+
7480
return services;
7581
}
7682

@@ -84,7 +90,7 @@ public static IServiceCollection AddSingleton(this IServiceCollection services,
8490
/// <param name="implementationType">The implementation type of the service.</param>
8591
/// <returns>A reference to this instance after the operation has completed.</returns>
8692
/// <seealso cref="ServiceLifetime.Transient"/>
87-
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be null.</exception>
93+
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be <see langword="null"/>.</exception>
8894
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, Type implementationType)
8995
{
9096
if (services == null)
@@ -106,7 +112,7 @@ public static IServiceCollection AddTransient(this IServiceCollection services,
106112
/// <param name="serviceType">The type of the service to register and the implementation to use.</param>
107113
/// <returns>A reference to this instance after the operation has completed.</returns>
108114
/// <seealso cref="ServiceLifetime.Transient"/>
109-
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be null.</exception>
115+
/// <exception cref="ArgumentNullException"><paramref name="services"/> can't be <see langword="null"/>.</exception>
110116
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType)
111117
{
112118
if (services == null)
@@ -123,7 +129,7 @@ public static IServiceCollection AddTransient(this IServiceCollection services,
123129
/// </summary>
124130
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
125131
/// <param name="descriptor">The <see cref="ServiceDescriptor"/> to add.</param>
126-
/// <exception cref="ArgumentNullException"><paramref name="collection"/> or <paramref name="descriptor"/> can't be null.</exception>
132+
/// <exception cref="ArgumentNullException"><paramref name="collection"/> or <paramref name="descriptor"/> can't be <see langword="null"/>.</exception>
127133
public static void TryAdd(this IServiceCollection collection, ServiceDescriptor descriptor)
128134
{
129135
if (collection == null)
@@ -137,6 +143,7 @@ public static void TryAdd(this IServiceCollection collection, ServiceDescriptor
137143
}
138144

139145
int count = collection.Count;
146+
140147
for (int index = 0; index < count; index++)
141148
{
142149
if (collection[index].ServiceType == descriptor.ServiceType)
@@ -167,7 +174,7 @@ public static void TryAdd(this IServiceCollection collection, ServiceDescriptor
167174
/// of multiple implementation types.
168175
/// </remarks>
169176
/// <exception cref="ArgumentException">Implementation type cannot be 'implementationType' because it is indistinguishable from other services registered for 'descriptor.ServiceType'.</exception>
170-
/// <exception cref="ArgumentNullException"><paramref name="services"/> or <paramref name="descriptor"/> can't be null.</exception>
177+
/// <exception cref="ArgumentNullException"><paramref name="services"/> or <paramref name="descriptor"/> can't be <see langword="null"/>.</exception>
171178
public static void TryAddEnumerable(this IServiceCollection services, ServiceDescriptor descriptor)
172179
{
173180
if (services == null)
@@ -182,18 +189,20 @@ public static void TryAddEnumerable(this IServiceCollection services, ServiceDes
182189

183190
Type implementationType = descriptor.GetImplementationType();
184191

185-
if (implementationType == typeof(object) ||
186-
implementationType == descriptor.ServiceType)
192+
if (implementationType == typeof(object)
193+
|| implementationType == descriptor.ServiceType)
187194
{
188195
throw new ArgumentException();
189196
}
190197

191198
int count = services.Count;
199+
192200
for (int index = 0; index < count; index++)
193201
{
194202
ServiceDescriptor service = services[index];
195-
if (service.ServiceType == descriptor.ServiceType &&
196-
service.GetImplementationType() == implementationType)
203+
204+
if (service.ServiceType == descriptor.ServiceType
205+
&& service.GetImplementationType() == implementationType)
197206
{
198207
// Already added
199208
return;
@@ -220,7 +229,7 @@ public static void TryAddEnumerable(this IServiceCollection services, ServiceDes
220229
/// <see cref="TryAddEnumerable(IServiceCollection, ServiceDescriptor)"/> will prevent registration
221230
/// of multiple implementation types.
222231
/// </remarks>
223-
/// <exception cref="ArgumentNullException"><paramref name="services"/> or <paramref name="descriptors"/> can't be null.</exception>
232+
/// <exception cref="ArgumentNullException"><paramref name="services"/> or <paramref name="descriptors"/> can't be <see langword="null"/>.</exception>
224233
public static void TryAddEnumerable(this IServiceCollection services, IEnumerable descriptors)
225234
{
226235
if (services == null)
@@ -246,7 +255,7 @@ public static void TryAddEnumerable(this IServiceCollection services, IEnumerabl
246255
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
247256
/// <param name="descriptor">The <see cref="ServiceDescriptor"/> to replace with.</param>
248257
/// <returns>The <see cref="IServiceCollection"/> for chaining.</returns>
249-
/// <exception cref="ArgumentNullException"><paramref name="collection"/> or <paramref name="descriptor"/> can't be null.</exception>
258+
/// <exception cref="ArgumentNullException"><paramref name="collection"/> or <paramref name="descriptor"/> can't be <see langword="null"/>.</exception>
250259
public static IServiceCollection Replace(this IServiceCollection collection, ServiceDescriptor descriptor)
251260
{
252261
if (collection == null)
@@ -261,6 +270,7 @@ public static IServiceCollection Replace(this IServiceCollection collection, Ser
261270

262271
// Remove existing
263272
int count = collection.Count;
273+
264274
for (int index = 0; index < count; index++)
265275
{
266276
if (collection[index].ServiceType == descriptor.ServiceType)
@@ -271,6 +281,7 @@ public static IServiceCollection Replace(this IServiceCollection collection, Ser
271281
}
272282

273283
collection.Add(descriptor);
284+
274285
return collection;
275286
}
276287

@@ -280,7 +291,7 @@ public static IServiceCollection Replace(this IServiceCollection collection, Ser
280291
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
281292
/// <param name="serviceType">The service type to remove.</param>
282293
/// <returns>The <see cref="IServiceCollection"/> for chaining.</returns>
283-
/// <exception cref="ArgumentNullException"><paramref name="serviceType"/> can't be null.</exception>
294+
/// <exception cref="ArgumentNullException"><paramref name="serviceType"/> can't be <see langword="null"/>.</exception>
284295
public static IServiceCollection RemoveAll(this IServiceCollection collection, Type serviceType)
285296
{
286297
if (serviceType == null)
@@ -291,6 +302,7 @@ public static IServiceCollection RemoveAll(this IServiceCollection collection, T
291302
for (int index = collection.Count - 1; index >= 0; index--)
292303
{
293304
ServiceDescriptor descriptor = collection[index];
305+
294306
if (descriptor.ServiceType == serviceType)
295307
{
296308
collection.RemoveAt(index);
@@ -300,4 +312,4 @@ public static IServiceCollection RemoveAll(this IServiceCollection collection, T
300312
return collection;
301313
}
302314
}
303-
}
315+
}

0 commit comments

Comments
 (0)