mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
Code quality changes
This commit is contained in:
parent
f07ed83722
commit
610f45d082
189 changed files with 4609 additions and 5203 deletions
|
@ -30,11 +30,9 @@ using GreenshotPlugin.Core;
|
|||
|
||||
namespace GreenshotConfluencePlugin {
|
||||
public class EnumDisplayer : IValueConverter {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EnumDisplayer));
|
||||
|
||||
private Type type;
|
||||
private IDictionary displayValues;
|
||||
private IDictionary reverseValues;
|
||||
private Type _type;
|
||||
private IDictionary _displayValues;
|
||||
private IDictionary _reverseValues;
|
||||
|
||||
public EnumDisplayer() {
|
||||
}
|
||||
|
@ -44,22 +42,30 @@ namespace GreenshotConfluencePlugin {
|
|||
}
|
||||
|
||||
public Type Type {
|
||||
get { return type; }
|
||||
get { return _type; }
|
||||
set {
|
||||
if (!value.IsEnum) {
|
||||
throw new ArgumentException("parameter is not an Enumerated type", "value");
|
||||
throw new ArgumentException("parameter is not an Enumerated type", nameof(value));
|
||||
}
|
||||
type = value;
|
||||
_type = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<string> DisplayNames {
|
||||
get {
|
||||
reverseValues = (IDictionary) Activator.CreateInstance(typeof(Dictionary<,>).GetGenericTypeDefinition().MakeGenericType(typeof(string),type));
|
||||
|
||||
displayValues = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>).GetGenericTypeDefinition().MakeGenericType(type, typeof(string)));
|
||||
|
||||
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
|
||||
var genericTypeDefinition = typeof(Dictionary<,>).GetGenericTypeDefinition();
|
||||
if (genericTypeDefinition != null)
|
||||
{
|
||||
_reverseValues = (IDictionary) Activator.CreateInstance(genericTypeDefinition.MakeGenericType(typeof(string),_type));
|
||||
}
|
||||
|
||||
var typeDefinition = typeof(Dictionary<,>).GetGenericTypeDefinition();
|
||||
if (typeDefinition != null)
|
||||
{
|
||||
_displayValues = (IDictionary)Activator.CreateInstance(typeDefinition.MakeGenericType(_type, typeof(string)));
|
||||
}
|
||||
|
||||
var fields = _type.GetFields(BindingFlags.Public | BindingFlags.Static);
|
||||
foreach (var field in fields) {
|
||||
DisplayKeyAttribute[] a = (DisplayKeyAttribute[])field.GetCustomAttributes(typeof(DisplayKeyAttribute), false);
|
||||
|
||||
|
@ -67,25 +73,19 @@ namespace GreenshotConfluencePlugin {
|
|||
object enumValue = field.GetValue(null);
|
||||
|
||||
string displayString;
|
||||
if (displayKey != null && Language.hasKey(displayKey)) {
|
||||
if (displayKey != null && Language.HasKey(displayKey)) {
|
||||
displayString = Language.GetString(displayKey);
|
||||
}
|
||||
if (displayKey != null) {
|
||||
displayString = displayKey;
|
||||
} else {
|
||||
displayString = enumValue.ToString();
|
||||
}
|
||||
|
||||
if (displayString != null) {
|
||||
displayValues.Add(enumValue, displayString);
|
||||
reverseValues.Add(displayString, enumValue);
|
||||
}
|
||||
displayString = displayKey ?? enumValue.ToString();
|
||||
|
||||
_displayValues.Add(enumValue, displayString);
|
||||
_reverseValues.Add(displayString, enumValue);
|
||||
}
|
||||
return new List<string>((IEnumerable<string>)displayValues.Values).AsReadOnly();
|
||||
return new List<string>((IEnumerable<string>)_displayValues.Values).AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDisplayKeyValue(DisplayKeyAttribute[] a) {
|
||||
private static string GetDisplayKeyValue(DisplayKeyAttribute[] a) {
|
||||
if (a == null || a.Length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -94,11 +94,11 @@ namespace GreenshotConfluencePlugin {
|
|||
}
|
||||
|
||||
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return displayValues[value];
|
||||
return _displayValues[value];
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return reverseValues[value];
|
||||
return _reverseValues[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue