Skip to content

Commit

Permalink
IManualMetadataProvider.SetMetadataContainer use cached setter expres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
petriashev committed Apr 19, 2024
1 parent a0b77c8 commit 28a4dad
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MicroElements.Metadata/Metadata/IMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using MicroElements.Collections.Cache;
using MicroElements.Reflection.Expressions;

namespace MicroElements.Metadata
Expand Down Expand Up @@ -50,7 +51,10 @@ IPropertyContainer IMetadataProvider.GetMetadataContainer(bool autoCreate)
/// <inheritdoc />
void IMetadataProvider.SetMetadataContainer(IPropertyContainer metadata)
{
Action<object, IPropertyContainer> propertySetter = Expressions.GetPropertySetter<IPropertyContainer>(this.GetType(), nameof(Metadata));
Type realType = this.GetType();
Action<object, IPropertyContainer> propertySetter = Cache
.Instance<Type, Action<object, IPropertyContainer>>()
.GetOrAdd(realType, type => Expressions.GetPropertySetter<IPropertyContainer>(type, nameof(Metadata)));
propertySetter.Invoke(this, metadata);
}
}
Expand Down

0 comments on commit 28a4dad

Please sign in to comment.