Apply R# clean-up for reliability (#877)
* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
This commit is contained in:
1 parent
b9b0f7c8df
commit
6ffa63b923
236 files changed
+14194
-7278
No files matched your search
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Xml
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class XmlNormalizedAttribute : XmlRangedAttribute
|
||||
{
|
||||
public XmlNormalizedAttribute() : base(0, 1) {}
|
||||
public XmlNormalizedAttribute() : base(0, 1) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,11 +67,20 @@ namespace VocaluxeLib.Xml
|
||||
public bool IsValid(Type type, object value)
|
||||
{
|
||||
if (type == typeof(int))
|
||||
{
|
||||
return ((int)value).IsInRange(Min, Max);
|
||||
}
|
||||
|
||||
if (type == typeof(float))
|
||||
{
|
||||
return ((float)value).IsInRange(Min, Max);
|
||||
}
|
||||
|
||||
if (type == typeof(double))
|
||||
{
|
||||
return ((double)value).IsInRange(Min, Max);
|
||||
}
|
||||
|
||||
Debug.Assert(false, "Ranged attribute has invalid type");
|
||||
return false;
|
||||
}
|
||||
@@ -99,11 +108,18 @@ namespace VocaluxeLib.Xml
|
||||
{
|
||||
Type subType;
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
subType = type.GetGenericArguments().Last();
|
||||
}
|
||||
else if (type.IsArray)
|
||||
{
|
||||
subType = type.GetElementType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return subType.GetTypeName();
|
||||
}
|
||||
|
||||
@@ -114,7 +130,7 @@ namespace VocaluxeLib.Xml
|
||||
/// <param name="field">Field descrived by the struct</param>
|
||||
private static void _FillInfo(ref SFieldInfo info, MemberInfo field)
|
||||
{
|
||||
XmlAttributeAttribute attribute = field.GetAttribute<XmlAttributeAttribute>();
|
||||
var attribute = field.GetAttribute<XmlAttributeAttribute>();
|
||||
if (attribute != null)
|
||||
{
|
||||
info.IsAttribute = true;
|
||||
@@ -122,12 +138,14 @@ namespace VocaluxeLib.Xml
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlElementAttribute element = field.GetAttribute<XmlElementAttribute>();
|
||||
var element = field.GetAttribute<XmlElementAttribute>();
|
||||
if (element != null)
|
||||
{
|
||||
info.Name = element.ElementName;
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlArrayAttribute array = field.GetAttribute<XmlArrayAttribute>();
|
||||
var array = field.GetAttribute<XmlArrayAttribute>();
|
||||
if (array != null)
|
||||
{
|
||||
Debug.Assert(info.Type.IsList() || info.Type.IsArray, "Only lists and arrays can have the array attribute");
|
||||
@@ -137,35 +155,54 @@ namespace VocaluxeLib.Xml
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(info.Name))
|
||||
{
|
||||
info.Name = field.Name;
|
||||
XmlAltNameAttribute altName = field.GetAttribute<XmlAltNameAttribute>();
|
||||
}
|
||||
|
||||
var altName = field.GetAttribute<XmlAltNameAttribute>();
|
||||
if (altName != null)
|
||||
{
|
||||
info.AltName = altName.AltName;
|
||||
}
|
||||
|
||||
if (info.Type.IsGenericType)
|
||||
{
|
||||
info.SubType = info.Type.GetGenericArguments().Last();
|
||||
}
|
||||
else if (info.Type.IsArray)
|
||||
{
|
||||
info.SubType = info.Type.GetElementType();
|
||||
}
|
||||
|
||||
if (info.Type.IsList() || info.Type.IsArray)
|
||||
{
|
||||
if (!info.IsList)
|
||||
{
|
||||
Debug.Assert(!field.HasAttribute<XmlArrayAttribute>(), "A field cannot have an XmlElement- and XmlArray-Attribute");
|
||||
if (info.Type.IsArray && info.SubType == typeof(byte))
|
||||
{
|
||||
info.IsByteArray = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.IsEmbeddedList = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlArrayItemAttribute arrayItem = field.GetAttribute<XmlArrayItemAttribute>();
|
||||
var arrayItem = field.GetAttribute<XmlArrayItemAttribute>();
|
||||
if (arrayItem != null && !string.IsNullOrEmpty(arrayItem.ElementName))
|
||||
{
|
||||
info.ArrayItemName = arrayItem.ElementName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (info.Type.IsNullable())
|
||||
{
|
||||
info.IsNullable = true;
|
||||
}
|
||||
else if (info.Type.IsDictionary())
|
||||
{
|
||||
Debug.Assert(info.Type.GetGenericArguments()[0] == typeof(string), "Keys of dictionaries must be strings");
|
||||
@@ -173,13 +210,16 @@ namespace VocaluxeLib.Xml
|
||||
}
|
||||
|
||||
if (field.HasAttribute<XmlNormalizedAttribute>())
|
||||
{
|
||||
Debug.Assert(info.Type == typeof(float) || (info.IsNullable && info.SubType == typeof(float)), "Only floats can be normalized");
|
||||
info.Ranged = field.GetAttribute<XmlRangedAttribute>();
|
||||
Type tmpType = info.IsNullable ? info.SubType : info.Type;
|
||||
Debug.Assert(info.Ranged == null || tmpType == typeof(int) || tmpType == typeof(float) || tmpType == typeof(double),
|
||||
"Only ints,floats and double can be ranged");
|
||||
}
|
||||
|
||||
DefaultValueAttribute defAttr = field.GetAttribute<DefaultValueAttribute>();
|
||||
info.Ranged = field.GetAttribute<XmlRangedAttribute>();
|
||||
var tmpType = info.IsNullable ? info.SubType : info.Type;
|
||||
Debug.Assert(info.Ranged == null || tmpType == typeof(int) || tmpType == typeof(float) || tmpType == typeof(double),
|
||||
"Only ints,floats and double can be ranged");
|
||||
|
||||
var defAttr = field.GetAttribute<DefaultValueAttribute>();
|
||||
if (defAttr != null)
|
||||
{
|
||||
Debug.Assert(!info.Type.IsList(), "Lists cannot have a default value");
|
||||
@@ -202,26 +242,37 @@ namespace VocaluxeLib.Xml
|
||||
{
|
||||
List<SFieldInfo> result;
|
||||
if (_CacheFields.TryGetValue(type, out result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = new List<SFieldInfo>();
|
||||
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (FieldInfo field in fields)
|
||||
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (field.HasAttribute<XmlIgnoreAttribute>() || field.Name.EndsWith("Specified"))
|
||||
{
|
||||
continue;
|
||||
SFieldInfo info = new SFieldInfo(field);
|
||||
}
|
||||
|
||||
var info = new SFieldInfo(field);
|
||||
_FillInfo(ref info, field);
|
||||
result.Add(info);
|
||||
}
|
||||
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (PropertyInfo property in properties)
|
||||
|
||||
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (property.HasAttribute<XmlIgnoreAttribute>() || property.Name.EndsWith("Specified") || !property.CanRead || !property.CanWrite)
|
||||
{
|
||||
continue;
|
||||
SFieldInfo info = new SFieldInfo(property);
|
||||
}
|
||||
|
||||
var info = new SFieldInfo(property);
|
||||
_FillInfo(ref info, property);
|
||||
result.Add(info);
|
||||
}
|
||||
|
||||
_CacheFields.Add(type, result);
|
||||
return result;
|
||||
}
|
||||
@@ -246,16 +297,24 @@ namespace VocaluxeLib.Xml
|
||||
{
|
||||
string name;
|
||||
if (_CacheTypeName.TryGetValue(type, out name))
|
||||
{
|
||||
return name;
|
||||
XmlTypeAttribute att = type.GetAttribute<XmlTypeAttribute>();
|
||||
}
|
||||
|
||||
var att = type.GetAttribute<XmlTypeAttribute>();
|
||||
if (att != null)
|
||||
{
|
||||
name = att.TypeName;
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = type.Name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = type.Name;
|
||||
}
|
||||
|
||||
_CacheTypeName.Add(type, name);
|
||||
return name;
|
||||
}
|
||||
@@ -279,7 +338,7 @@ namespace VocaluxeLib.Xml
|
||||
/// <returns></returns>
|
||||
public static T GetAttribute<T>(this ICustomAttributeProvider field) where T : class
|
||||
{
|
||||
object[] attributes = field.GetCustomAttributes(typeof(T), false);
|
||||
var attributes = field.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length == 0 ? null : (T)attributes[0];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user