Я использую комбинацию нескольких из предложений выше, объединенный с некоторым кэшированием. Теперь, я получил идею от некоторого кода, что я нашел где-нибудь в сети, но я не могу ни помнить, где я получил его, или найдите его. Таким образом, если кто-либо когда-нибудь находит что-то, что выглядит подобным, прокомментируйте с атрибуцией.
Так или иначе, использование включает конвертеры типов, поэтому если Вы связываете с UI, это 'просто работает'. Вы можете расширенный с помощью шаблона Jakub для быстрого поиска кода путем инициализации из конвертера типов в статические методы.
основное использование было бы похоже на это
[TypeConverter(typeof(CustomEnumTypeConverter<MyEnum>))]
public enum MyEnum
{
// The custom type converter will use the description attribute
[Description("A custom description")]
ValueWithCustomDescription,
// This will be exposed exactly.
Exact
}
, код для пользовательского перечислимого конвертера типов следует:
public class CustomEnumTypeConverter<T> : EnumConverter
where T : struct
{
private static readonly Dictionary<T,string> s_toString =
new Dictionary<T, string>();
private static readonly Dictionary<string, T> s_toValue =
new Dictionary<string, T>();
private static bool s_isInitialized;
static CustomEnumTypeConverter()
{
System.Diagnostics.Debug.Assert(typeof(T).IsEnum,
"The custom enum class must be used with an enum type.");
}
public CustomEnumTypeConverter() : base(typeof(T))
{
if (!s_isInitialized)
{
Initialize();
s_isInitialized = true;
}
}
protected void Initialize()
{
foreach (T item in Enum.GetValues(typeof(T)))
{
string description = GetDescription(item);
s_toString[item] = description;
s_toValue[description] = item;
}
}
private static string GetDescription(T optionValue)
{
var optionDescription = optionValue.ToString();
var optionInfo = typeof(T).GetField(optionDescription);
if (Attribute.IsDefined(optionInfo, typeof(DescriptionAttribute)))
{
var attribute =
(DescriptionAttribute)Attribute.
GetCustomAttribute(optionInfo, typeof(DescriptionAttribute));
return attribute.Description;
}
return optionDescription;
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture,
object value, Type destinationType)
{
var optionValue = (T)value;
if (destinationType == typeof(string) &&
s_toString.ContainsKey(optionValue))
{
return s_toString[optionValue];
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
var stringValue = value as string;
if (!string.IsNullOrEmpty(stringValue) && s_toValue.ContainsKey(stringValue))
{
return s_toValue[stringValue];
}
return base.ConvertFrom(context, culture, value);
}
}
}
Попробуйте следующее:
:ruby finder.rescan!
Вы можете сопоставить это к чему-то, если вам нужно делать это часто.
В Fuzzy Finder есть команда под названием: FufRenewCache
В более ранних версиях Fuzzy Finder было нечто подобное, но я не могу вспомнить команду сейчас.
Просто попробуйте ввести
: Fuf или : FuzzyFinder
И посмотрите, какие возможные команды показаны в Vim.