Skip to content

Commit fdee5ff

Browse files
committed
🐛 fixed deep clone bug
1 parent 6732738 commit fdee5ff

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/EasyCaching.InMemory/Internal/DeepClonerGenerator.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,26 @@ internal static object GenerateClonerInternal(Type realType, bool asObject)
491491
{
492492
return GenerateProcessMethod(realType, asObject && realType.IsValueType);
493493
}
494-
494+
495+
// slow, but hardcore method to set readonly field
496+
internal static void ForceSetField(FieldInfo field, object obj, object value)
497+
{
498+
var fieldInfo = field.GetType().GetTypeInfo().GetDeclaredField("m_fieldAttributes");
499+
500+
// TODO: think about it
501+
// nothing to do :( we should a throw an exception, but it is no good for user
502+
if (fieldInfo == null)
503+
return;
504+
var ov = fieldInfo.GetValue(field);
505+
if (!(ov is FieldAttributes))
506+
return;
507+
var v = (FieldAttributes)ov;
508+
509+
fieldInfo.SetValue(field, v & ~FieldAttributes.InitOnly);
510+
field.SetValue(obj, value);
511+
fieldInfo.SetValue(field, v);
512+
}
513+
495514
private static object GenerateProcessMethod(Type type, bool unboxStruct)
496515
{
497516
if (type.IsArray)

src/EasyCaching.InMemory/Internal/InMemoryCaching.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public CacheValue<T> Get<T>(string key)
7171
var value = cacheEntry.GetValue<T>();
7272
return new CacheValue<T>(value, true);
7373
}
74-
catch
75-
{
74+
catch (Exception ex)
75+
{
76+
System.Diagnostics.Debug.WriteLine($"some error herer, message = {ex.Message}");
7677
return CacheValue<T>.NoValue;
7778
}
7879
}

src/EasyCaching.ResponseCaching/EasyCachingResponseCachingServiceCollectionExtensions.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@ public static class EasyCachingResponseCachingServiceCollectionExtensions
1313
{
1414
/// <summary>
1515
/// Adds the EasyCaching response caching.
16-
/// </summary>
17-
/// <returns>The easy caching response caching.</returns>
16+
/// </summary>
1817
/// <param name="services">Services.</param>
19-
/// <param name="name">Provider name.</param>
18+
/// <param name="name">The provider name that will use to store the response.</param>
2019
public static IServiceCollection AddEasyCachingResponseCaching(this IServiceCollection services, string name) =>
2120
services.AddEasyCachingResponseCaching(
2221
x => { }, name
2322
);
2423

2524
/// <summary>
2625
/// Adds the EasyCaching response caching.
27-
/// </summary>
28-
/// <returns>The easy caching response caching.</returns>
26+
/// </summary>
2927
/// <param name="services">Services.</param>
30-
/// <param name="action">Action.</param>
31-
/// <param name="name">Provider name.</param>
32-
public static IServiceCollection AddEasyCachingResponseCaching(this IServiceCollection services,
33-
Action<ResponseCachingOptions> action, string name)
28+
/// <param name="action">Configure response caching settings.</param>
29+
/// <param name="name">The provider name that will use to store the response.</param>
30+
public static IServiceCollection AddEasyCachingResponseCaching(
31+
this IServiceCollection services
32+
, Action<ResponseCachingOptions> action
33+
, string name
34+
)
3435
{
3536
ArgumentCheck.NotNull(services, nameof(services));
3637

0 commit comments

Comments
 (0)