Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 3a898a09 authored by Harald Martini's avatar Harald Martini Committed by Markus Quaritsch
Browse files

Cache attributes of ModalResultField in Dictionary

(cherry picked from commit 1197335f)
parent fe7ff3ea
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;
......@@ -473,6 +474,8 @@ 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();
......@@ -480,7 +483,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public static string GetCaption(this ModalResultField field)
{
return GetAttribute(field).Caption ?? GetAttribute(field).Name ?? field.ToString();
var attribute = GetAttribute(field);
return attribute.Caption ?? attribute.Name ?? field.ToString();
}
public static string GetShortCaption(this ModalResultField field)
......@@ -496,7 +500,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