From 28a4dad7ffc82b359b5af478fcca4278e6c22758 Mon Sep 17 00:00:00 2001 From: Alexey Petryashev Date: Fri, 19 Apr 2024 23:07:36 +0300 Subject: [PATCH] IManualMetadataProvider.SetMetadataContainer use cached setter expression --- src/MicroElements.Metadata/Metadata/IMetadataProvider.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MicroElements.Metadata/Metadata/IMetadataProvider.cs b/src/MicroElements.Metadata/Metadata/IMetadataProvider.cs index 53ab134..ad4552b 100644 --- a/src/MicroElements.Metadata/Metadata/IMetadataProvider.cs +++ b/src/MicroElements.Metadata/Metadata/IMetadataProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using MicroElements.Collections.Cache; using MicroElements.Reflection.Expressions; namespace MicroElements.Metadata @@ -50,7 +51,10 @@ IPropertyContainer IMetadataProvider.GetMetadataContainer(bool autoCreate) /// void IMetadataProvider.SetMetadataContainer(IPropertyContainer metadata) { - Action propertySetter = Expressions.GetPropertySetter(this.GetType(), nameof(Metadata)); + Type realType = this.GetType(); + Action propertySetter = Cache + .Instance>() + .GetOrAdd(realType, type => Expressions.GetPropertySetter(type, nameof(Metadata))); propertySetter.Invoke(this, metadata); } }