Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 8a240f24 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

adding caching dictionary for modal data fields

parent ac8e2dae
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@
*/
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Text.RegularExpressions;
using TUGraz.VectoCommon.Utils;
......@@ -402,6 +403,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public static class ModalResultFieldExtensionMethods
{
private static ConcurrentDictionary<ModalResultField, ModalResultFieldAttribute> _attributeDictionary =
new ConcurrentDictionary<ModalResultField, ModalResultFieldAttribute>();
public static string GetName(this ModalResultField field)
{
return GetAttribute(field).Name ?? field.ToString();
......@@ -425,7 +429,14 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public static ModalResultFieldAttribute GetAttribute(this ModalResultField field)
{
return (ModalResultFieldAttribute)Attribute.GetCustomAttribute(ForValue(field), typeof(ModalResultFieldAttribute));
var attributeCached = _attributeDictionary.TryGetValue(field, out var attribute);
if (attributeCached) {
return attribute;
} else {
attribute = (ModalResultFieldAttribute)Attribute.GetCustomAttribute(ForValue(field), typeof(ModalResultFieldAttribute));
_attributeDictionary.TryAdd(field, attribute);
}
return attribute;
}
private static MemberInfo ForValue(ModalResultField field)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment