优化缓存字典读取

This commit is contained in:
ww-rm
2025-04-18 23:55:08 +08:00
parent de6858ca48
commit 8f818416ba
2 changed files with 6 additions and 6 deletions

View File

@@ -85,9 +85,9 @@ namespace SpineViewer.Spine.SpineView
var props = new PropertyDescriptorCollection(TypeDescriptor.GetProperties(this, attributes, true).Cast<PropertyDescriptor>().ToArray());
foreach (var i in Spine.GetTrackIndices())
{
if (!pdCache.ContainsKey(i))
pdCache[i] = new TrackWrapperPropertyDescriptor(i, [new DisplayNameAttribute($"轨道 {i}")]);
props.Add(pdCache[i]);
if (!pdCache.TryGetValue(i, out var pd))
pdCache[i] = pd = new TrackWrapperPropertyDescriptor(i, [new DisplayNameAttribute($"轨道 {i}")]);
props.Add(pd);
}
return props;
}

View File

@@ -53,9 +53,9 @@ namespace SpineViewer.Spine.SpineView
var props = new PropertyDescriptorCollection(TypeDescriptor.GetProperties(this, attributes, true).Cast<PropertyDescriptor>().ToArray());
foreach (var name in Spine.SkinNames)
{
if (!pdCache.ContainsKey(name))
pdCache[name] = new SkinPropertyDescriptor(name, [new DisplayNameAttribute(name)]);
props.Add(pdCache[name]);
if (!pdCache.TryGetValue(name, out var pd))
pdCache[name] = pd = new SkinPropertyDescriptor(name, [new DisplayNameAttribute(name)]);
props.Add(pd);
}
return props;
}