Skip to content

Commit

Permalink
Improved logging for type scanning in XML serializer to make it clear…
Browse files Browse the repository at this point in the history
…er which message type and/or which of its properties caused a problem.
  • Loading branch information
Dahan, Udi committed Nov 3, 2010
1 parent 4789bb2 commit ad4798a
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public List<Type> MessageTypes
/// <param name="t"></param>
public void InitType(Type t)
{
logger.Debug("Initializing type: " + t.AssemblyQualifiedName);

if (t.IsSimpleType())
return;

Expand Down Expand Up @@ -130,6 +132,8 @@ public void InitType(Type t)

foreach (var p in props)
{
logger.Debug("Handling property: " + p.Name);

propertyInfoToLateBoundProperty[p] = DelegateFactory.Create(p);

if (!isKeyValuePair)
Expand All @@ -140,6 +144,8 @@ public void InitType(Type t)

foreach (var f in fields)
{
logger.Debug("Handling field: " + f.Name);

fieldInfoToLateBoundField[f] = DelegateFactory.Create(f);

if (!isKeyValuePair)
Expand All @@ -162,17 +168,17 @@ IEnumerable<PropertyInfo> GetAllPropertiesForType(Type t, bool isKeyValuePair)
foreach (var prop in t.GetProperties())
{
if (typeof(IList) == prop.PropertyType)
throw new NotSupportedException("IList is not a supported property type for serialization.Type: " + t.FullName + " Property: " + prop.Name);
throw new NotSupportedException("IList is not a supported property type for serialization, use List instead. Type: " + t.FullName + " Property: " + prop.Name);

var args = prop.PropertyType.GetGenericArguments();

if (args.Length == 1)
if (typeof(IList<>).MakeGenericType(args) == prop.PropertyType)
throw new NotSupportedException("IList<T> is not a supported property type for serialization. Type: " + t.FullName + " Property: " + prop.Name);
throw new NotSupportedException("IList<T> is not a supported property type for serialization, use List<T> instead. Type: " + t.FullName + " Property: " + prop.Name);

if (args.Length == 2)
if (typeof(IDictionary<,>).MakeGenericType(args) == prop.PropertyType)
throw new NotSupportedException("IDictionary<T, K> is not a supported property type for serialization. Type: " + t.FullName + " Property: " + prop.Name + ". Consider using a concrete Dictionary<T, K> instead.");
throw new NotSupportedException("IDictionary<T, K> is not a supported property type for serialization, use Dictionary<T,K> instead. Type: " + t.FullName + " Property: " + prop.Name + ". Consider using a concrete Dictionary<T, K> instead.");

if (!prop.CanWrite && !isKeyValuePair)
continue;
Expand Down

0 comments on commit ad4798a

Please sign in to comment.