Skip to content

Commit 2af26bd

Browse files
committed
Applied code style & cleanup
1 parent 01ff590 commit 2af26bd

12 files changed

Lines changed: 48 additions & 41 deletions

File tree

src/SpatialFocus.MethodCache.Fody/CecilExtension.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static class CecilExtension
1212
{
1313
public static MethodReference MakeGeneric(this MethodReference method, params TypeReference[] arguments)
1414
{
15+
if (method == null)
16+
{
17+
throw new ArgumentNullException(nameof(method));
18+
}
19+
1520
if (method.GenericParameters.Count != arguments.Length)
1621
{
1722
throw new ArgumentException("Invalid number of generic type arguments supplied");
@@ -34,6 +39,11 @@ public static MethodReference MakeGeneric(this MethodReference method, params Ty
3439

3540
public static MethodReference MakeHostInstanceGeneric(this MethodReference self, params TypeReference[] args)
3641
{
42+
if (self == null)
43+
{
44+
throw new ArgumentNullException(nameof(self));
45+
}
46+
3747
MethodReference reference = new MethodReference(self.Name, self.ReturnType, self.DeclaringType.MakeGenericInstanceType(args))
3848
{
3949
HasThis = self.HasThis, ExplicitThis = self.ExplicitThis, CallingConvention = self.CallingConvention,

src/SpatialFocus.MethodCache.Fody/ILProcessorContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public ILProcessorContext(ILProcessor processor, Instruction currentInstruction)
2222

2323
public ILProcessorContext Append(Func<ILProcessor, Instruction> action)
2424
{
25+
if (action == null)
26+
{
27+
throw new ArgumentNullException(nameof(action));
28+
}
29+
2530
Instruction instruction = action(Processor);
2631

2732
if (CurrentInstruction == null)

src/SpatialFocus.MethodCache.Fody/MemoryCache.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public static ILProcessorContext WeaveCreateKey(MethodWeavingContext methodWeavi
129129

130130
public static void WeaveSetBeforeReturns(MethodWeavingContext methodWeavingContext)
131131
{
132+
if (methodWeavingContext == null)
133+
{
134+
throw new ArgumentNullException(nameof(methodWeavingContext));
135+
}
136+
132137
MethodBody methodDefinitionBody = methodWeavingContext.MethodDefinition.Body;
133138

134139
List<Instruction> returns = methodDefinitionBody.Instructions.Where(x => x.OpCode == OpCodes.Ret).ToList();

src/SpatialFocus.MethodCache.Sample.Library/BasisSampleWeaved.cs renamed to src/SpatialFocus.MethodCache.Sample.Library/BasicSampleWeaved.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="BasisSampleWeaved.cs" company="Spatial Focus GmbH">
1+
// <copyright file="BasicSampleWeaved.cs" company="Spatial Focus GmbH">
22
// Copyright (c) Spatial Focus GmbH. All rights reserved.
33
// </copyright>
44

@@ -18,14 +18,12 @@ public BasicSampleWeaved(IMemoryCache memoryCache)
1818

1919
public int Add(int a, int b)
2020
{
21-
int value;
22-
2321
// Create a unique cache key, based on namespace, class name and method name as first parameter and corresponding
2422
// generic class parameters,generic method parameters and method parameters
2523
Tuple<string, int, int> key = new Tuple<string, int, int>("SpatialFocus.MethodCache.Sample.Library.BasicSample.Add", a, b);
2624

2725
// Check and return if a cached value exists for key
28-
if (MemoryCache.TryGetValue(key, out value))
26+
if (MemoryCache.TryGetValue(key, out int value))
2927
{
3028
return value;
3129
}

src/SpatialFocus.MethodCache.Sample/MyMemoryCache.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
namespace SpatialFocus.MethodCache.Sample
66
{
77
using System;
8-
using System.Runtime.CompilerServices;
98
using Microsoft.Extensions.Caching.Memory;
109
using Microsoft.Extensions.Logging;
1110

12-
public class MyMemoryCache : IMemoryCache
11+
public sealed class MyMemoryCache : IMemoryCache
1312
{
1413
public MyMemoryCache(IMemoryCache memoryCache, ILogger<MyMemoryCache> logger)
1514
{
1615
MemoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
1716
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
1817
}
1918

20-
protected ILogger<MyMemoryCache> Logger { get; }
19+
private ILogger<MyMemoryCache> Logger { get; }
2120

22-
protected IMemoryCache MemoryCache { get; }
21+
private IMemoryCache MemoryCache { get; }
2322

2423
public ICacheEntry CreateEntry(object key)
2524
{
@@ -29,8 +28,7 @@ public ICacheEntry CreateEntry(object key)
2928

3029
public void Dispose()
3130
{
32-
Dispose(true);
33-
GC.SuppressFinalize(this);
31+
MemoryCache?.Dispose();
3432
}
3533

3634
public void Remove(object key) => throw new NotImplementedException();
@@ -46,13 +44,5 @@ public bool TryGetValue(object key, out object value)
4644
Logger.LogInformation("Value for {key} found: {value}", key, value);
4745
return true;
4846
}
49-
50-
protected virtual void Dispose(bool disposing)
51-
{
52-
if (disposing)
53-
{
54-
MemoryCache?.Dispose();
55-
}
56-
}
5747
}
5848
}

src/SpatialFocus.MethodCache.Sample/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ namespace SpatialFocus.MethodCache.Sample
1212

1313
internal class Program
1414
{
15-
private static void Main(string[] args)
15+
private static void Main()
1616
{
1717
ServiceCollection serviceCollection = new ServiceCollection();
1818
serviceCollection.AddLogging(builder => builder.AddConsole());
1919
ServiceProvider buildServiceProvider = serviceCollection.BuildServiceProvider();
2020

21-
BasicSample basicSample = new BasicSample(new MyMemoryCache(new MemoryCache(new MemoryCacheOptions()),
22-
buildServiceProvider.GetRequiredService<ILogger<MyMemoryCache>>()));
21+
using MyMemoryCache memoryCacheBasicSample = new MyMemoryCache(new MemoryCache(new MemoryCacheOptions()),
22+
buildServiceProvider.GetRequiredService<ILogger<MyMemoryCache>>());
23+
BasicSample basicSample = new BasicSample(memoryCacheBasicSample);
2324

2425
basicSample.Add(1, 2);
2526
basicSample.Add(1, 2);
2627
basicSample.Add(3, 4);
2728

28-
GenericSample<int, object> genericSample = new GenericSample<int, object>(
29-
new MyMemoryCache(new MemoryCache(new MemoryCacheOptions()),
30-
buildServiceProvider.GetRequiredService<ILogger<MyMemoryCache>>()));
29+
using MyMemoryCache memoryCacheGenericSample = new MyMemoryCache(new MemoryCache(new MemoryCacheOptions()),
30+
buildServiceProvider.GetRequiredService<ILogger<MyMemoryCache>>());
31+
GenericSample<int, object> genericSample = new GenericSample<int, object>(memoryCacheGenericSample);
3132

3233
genericSample.Add<string, Attribute>(1, 2, 3, 4);
3334
genericSample.Add<string, Attribute>(1, 2, 3, 4);

src/SpatialFocus.MethodCache.SmokeTest/Class1.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Copyright (c) Spatial Focus GmbH. All rights reserved.
33
// </copyright>
44

5+
using System;
6+
7+
[assembly: CLSCompliant(false)]
8+
59
namespace SpatialFocus.MethodCache.SmokeTest
610
{
711
using System;

src/SpatialFocus.MethodCache.TestAssembly/Models/CustomObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override bool Equals(object obj)
2020
{
2121
CustomObject other = (CustomObject)obj;
2222

23-
return Age == other.Age && Name == other.Name;
23+
return other != null && Age == other.Age && Name == other.Name;
2424
}
2525

2626
public override int GetHashCode()

src/SpatialFocus.MethodCache.Tests/Mock/MockCacheEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace SpatialFocus.MethodCache.Tests.Mock
99
using Microsoft.Extensions.Caching.Memory;
1010
using Microsoft.Extensions.Primitives;
1111

12-
public class MockCacheEntry : ICacheEntry
12+
public sealed class MockCacheEntry : ICacheEntry
1313
{
1414
public IList<IChangeToken> ExpirationTokens { get; }
1515

src/SpatialFocus.MethodCache.Tests/Mock/MockMemoryCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SpatialFocus.MethodCache.Tests.Mock
77
using System.Collections.Generic;
88
using Microsoft.Extensions.Caching.Memory;
99

10-
public class MockMemoryCache : IMemoryCache
10+
public sealed class MockMemoryCache : IMemoryCache
1111
{
1212
public int CountGets { get; set; }
1313

0 commit comments

Comments
 (0)