Add type constraints for resource managers. Generalize detail panel.
This commit is contained in:
37
Assets/Cryville/Crtr/Browsing/UI/MetaPropertyExtensions.cs
Normal file
37
Assets/Cryville/Crtr/Browsing/UI/MetaPropertyExtensions.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.UI {
|
||||
internal static class MetaPropertyExtensions {
|
||||
public static IEnumerable<KeyValuePair<string, object>> EnumerateProperty(this MetaProperty prop, bool shortDistinct = false) {
|
||||
if (prop.Values.ContainsKey("distinct-primary") && shortDistinct) {
|
||||
yield return new KeyValuePair<string, object>(prop.Name, prop.Values["distinct-primary"]);
|
||||
if (prop.Values.ContainsKey("distinct-secondary")) {
|
||||
yield return new KeyValuePair<string, object>(prop.Name, prop.Values["distinct-secondary"]);
|
||||
if (prop.Values.ContainsKey("distinct-tertiary")) {
|
||||
yield return new KeyValuePair<string, object>(prop.Name, prop.Values["distinct-tertiary"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else yield return new KeyValuePair<string, object>(prop.Name, prop.MainValue);
|
||||
}
|
||||
public static IEnumerable<KeyValuePair<string, object>> EnumerateProperties(this IResourceMeta meta, bool shortDistinct = false) {
|
||||
foreach (var prop in meta.Properties) {
|
||||
foreach (var item in EnumerateProperty(prop, shortDistinct)) yield return item;
|
||||
}
|
||||
}
|
||||
public static IEnumerable<KeyValuePair<string, object>> EnumerateBasicProperties(this IResourceMeta meta, bool shortDistinct = false) {
|
||||
foreach (var prop in EnumerateProperties(meta, shortDistinct)) {
|
||||
if (prop.Value is string || prop.Value is IFormattable) {
|
||||
yield return new KeyValuePair<string, object>(prop.Key, prop.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static IEnumerable<KeyValuePair<string, T>> EnumerateProperties<T>(this IResourceMeta meta, bool shortDistinct = false) {
|
||||
return EnumerateProperties(meta, shortDistinct)
|
||||
.Where(prop => prop.Value is T)
|
||||
.Select(prop => new KeyValuePair<string, T>(prop.Key, (T)prop.Value));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user