diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs
index fac2f20c..f2f84ed8 100644
--- a/Vocaluxe/Base/CPlaylists.cs
+++ b/Vocaluxe/Base/CPlaylists.cs
@@ -78,8 +78,8 @@ namespace Vocaluxe.Base
foreach (string file in files)
{
CPlaylistFile playlist = new CPlaylistFile();
- if(playlist._Load(file))
- _Playlists.Add(playlist);
+ if (playlist._Load(file))
+ _Playlists.Add(playlist);
}
}
diff --git a/VocaluxeLib/Menu/CEqualizer.cs b/VocaluxeLib/Menu/CEqualizer.cs
index aa9e76da..010b8e80 100644
--- a/VocaluxeLib/Menu/CEqualizer.cs
+++ b/VocaluxeLib/Menu/CEqualizer.cs
@@ -149,7 +149,7 @@ namespace VocaluxeLib.Menu
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Space", ref ReflectionSpace);
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Height", ref ReflectionHeight);
- _Theme.Reflection = new SReflection( ReflectionHeight, ReflectionSpace);
+ _Theme.Reflection = new SReflection(ReflectionHeight, ReflectionSpace);
}
else
{
diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs
index 11e0c052..d3dc8906 100644
--- a/VocaluxeLib/Menu/CPlaylist.cs
+++ b/VocaluxeLib/Menu/CPlaylist.cs
@@ -52,7 +52,7 @@ namespace VocaluxeLib.Menu
CSong song = CBase.Songs.GetSongByID(SongID);
if (song == null)
throw new Exception("Can't find Song. This should never happen!");
- return new SPlaylistSong{Artist = song.Artist, Title = song.Title, GameMode = GameMode};
+ return new SPlaylistSong {Artist = song.Artist, Title = song.Title, GameMode = GameMode};
}
}
diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj
index 1dcf7041..de99965a 100644
--- a/VocaluxeLib/VocaluxeLib.csproj
+++ b/VocaluxeLib/VocaluxeLib.csproj
@@ -145,6 +145,7 @@
+
diff --git a/VocaluxeLib/Xml/CTypeExtensions.cs b/VocaluxeLib/Xml/CTypeExtensions.cs
index 2d937752..15a3c564 100644
--- a/VocaluxeLib/Xml/CTypeExtensions.cs
+++ b/VocaluxeLib/Xml/CTypeExtensions.cs
@@ -1,4 +1,21 @@
-using System;
+#region license
+// This file is part of Vocaluxe.
+//
+// Vocaluxe is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Vocaluxe is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Vocaluxe. If not, see .
+#endregion
+
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
@@ -9,6 +26,9 @@ using System.Xml.Serialization;
namespace VocaluxeLib.Xml
{
// ReSharper disable InconsistentNaming
+ ///
+ /// Attribute containing an alternative name in the xml files during deserialization
+ ///
[AttributeUsage(AttributeTargets.Field)]
public class XmlAltNameAttribute : Attribute
{
@@ -20,9 +40,15 @@ namespace VocaluxeLib.Xml
}
}
+ ///
+ /// Attribute for float fields to enforce normalized (0<=x<=1) values
+ ///
[AttributeUsage(AttributeTargets.Field)]
public class XmlNormalizedAttribute : Attribute {}
+ ///
+ /// Attribute for int fields to enforce values in the given range
+ ///
[AttributeUsage(AttributeTargets.Field)]
public class XmlRangedAttribute : Attribute
{
@@ -38,58 +64,9 @@ namespace VocaluxeLib.Xml
// ReSharper restore InconsistentNaming
- public struct SFieldInfo
- {
- private readonly FieldInfo _Field;
- private readonly PropertyInfo _Property;
-
- public Type Type
- {
- get { return _Field != null ? _Field.FieldType : _Property.PropertyType; }
- }
- public string Name;
- public string AltName;
- public object DefaultValue;
- public bool HasDefaultValue;
- public bool IsAttribute;
- public bool IsList; //List with child elements ()
- public bool IsEmbeddedList; //List w/o child elements()
- public bool IsDictionary; //List where the element names are the keys
- public bool IsByteArray; // Byte arrays w/o XmlArrayAttribute are serialized as Base64-Encoded strings
- public bool IsNullable;
- public bool IsNormalized;
- public XmlRangedAttribute Ranged;
- public Type SubType;
- public string ArrayItemName;
-
- public SFieldInfo(FieldInfo field)
- : this()
- {
- _Field = field;
- }
-
- public SFieldInfo(PropertyInfo property)
- : this()
- {
- _Property = property;
- }
-
- public void SetValue(object o, object value)
- {
- if (_Field != null)
- _Field.SetValue(o, value);
- else
- _Property.SetValue(o, value, new object[] {});
- }
-
- public object GetValue(object o)
- {
- return (_Field != null) ? _Field.GetValue(o) : _Property.GetValue(o, new object[] {});
- }
- }
-
public static class CTypeExtensions
{
+ // Cache for fields to speed up access to common types
private static readonly Dictionary> _CacheFields = new Dictionary>();
private static readonly Dictionary _CacheTypeName = new Dictionary();
@@ -110,6 +87,11 @@ namespace VocaluxeLib.Xml
return subType.GetTypeName();
}
+ ///
+ /// Fills the struct with information about the field
+ ///
+ /// Struct to fill
+ /// Field descrived by the struct
private static void _FillInfo(ref SFieldInfo info, MemberInfo field)
{
XmlAttributeAttribute attribute = field.GetAttribute();
@@ -193,6 +175,11 @@ namespace VocaluxeLib.Xml
}
}
+ ///
+ /// Returns a collection with infos about all fields and properties of the type that can be (xml-)serialized
+ ///
+ /// Type to get information about
+ ///
public static IEnumerable GetFieldInfos(this Type type)
{
List result;
@@ -221,11 +208,22 @@ namespace VocaluxeLib.Xml
return result;
}
+ ///
+ /// Returns a collection with infos about all fields and properties of the type that can be (xml-)serialized but limits it to those which are (xml)-nodes or attributes
+ ///
+ /// Type to get information about
+ /// True to return infos about attributes, false for nodes
+ ///
public static List GetFields(this Type type, bool attributes)
{
return GetFieldInfos(type).Where(f => f.IsAttribute == attributes).ToList();
}
+ ///
+ /// Gets the (xml)-type name for the type (influenced by XmlTypeAttributes)
+ ///
+ ///
+ ///
public static string GetTypeName(this Type type)
{
string name;
@@ -244,11 +242,23 @@ namespace VocaluxeLib.Xml
return name;
}
+ ///
+ /// Returns true if the field has the attribute
+ ///
+ /// Attribute type
+ ///
+ ///
public static bool HasAttribute(this ICustomAttributeProvider field)
{
return field.GetCustomAttributes(typeof(T), false).Length > 0;
}
+ ///
+ /// Gets the first attribute with the given type or null if none found
+ ///
+ /// Attribute type
+ ///
+ ///
public static T GetAttribute(this ICustomAttributeProvider field) where T : class
{
object[] attributes = field.GetCustomAttributes(typeof(T), false);
diff --git a/VocaluxeLib/Xml/CXmlDeserializer.cs b/VocaluxeLib/Xml/CXmlDeserializer.cs
index 6b1beb59..a6299991 100644
--- a/VocaluxeLib/Xml/CXmlDeserializer.cs
+++ b/VocaluxeLib/Xml/CXmlDeserializer.cs
@@ -1,4 +1,21 @@
-using System;
+#region license
+// This file is part of Vocaluxe.
+//
+// Vocaluxe is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Vocaluxe is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Vocaluxe. If not, see .
+#endregion
+
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
@@ -14,6 +31,11 @@ namespace VocaluxeLib.Xml
public class CXmlDeserializer
{
#region Debug Helpers
+ ///
+ /// Returns the xPath from root to the node
+ ///
+ ///
+ ///
private string _GetXPath(XmlNode node)
{
StringBuilder builder = new StringBuilder();
@@ -39,6 +61,11 @@ namespace VocaluxeLib.Xml
throw new ArgumentException("Node was not in a document");
}
+ ///
+ /// Returns an index as a string or empty string if the node name is sufficient to identify the node
+ ///
+ ///
+ ///
private string _FindElementIndex(XmlNode element)
{
XmlNode parentNode = element.ParentNode;
@@ -60,7 +87,15 @@ namespace VocaluxeLib.Xml
}
#endregion Debug Helpers
- private object _GetValue(XmlNode node, Type type, string arrayItemName = null, object result = null)
+ ///
+ /// Returns the value if the given node
+ ///
+ /// Node to process
+ /// Type of the object at that node
+ /// Name of the sub nodes for array types(Array,List,Dictionary), can be set by XmlArrayItemAttribute and defaults to the type name
+ /// If given, no new class is created and value is used instead
+ ///
+ private object _GetValue(XmlNode node, Type type, string subName = null, object value = null)
{
if (type.IsEnum)
{
@@ -83,12 +118,13 @@ namespace VocaluxeLib.Xml
if (!node.HasChildNodes)
return null;
Type subType = type.GetGenericArguments()[0];
- return _GetValue(node, subType, arrayItemName, result);
+ return _GetValue(node, subType, subName, value);
}
if (type.IsList() || type.IsArray)
{
Type subType = type.IsArray ? type.GetElementType() : type.GetGenericArguments()[0];
- String subName = arrayItemName ?? subType.GetTypeName();
+ if (subName == null)
+ subName = subType.GetTypeName();
subName = subName.ToLowerInvariant();
List