Skip to content

Commit c91e958

Browse files
Improve FieldInjectorException and PropertyInjectorException message
1 parent 378fe00 commit c91e958

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using System;
2+
using System.Reflection;
23

34
namespace Reflex.Exceptions
45
{
56
internal sealed class FieldInjectorException : Exception
67
{
7-
public FieldInjectorException(Exception e) : base(e.Message)
8+
public FieldInjectorException(FieldInfo field, Exception e) : base(BuildMessage(field, e))
89
{
910
}
11+
12+
private static string BuildMessage(FieldInfo field, Exception e)
13+
{
14+
var fieldDescription = $"'{field.DeclaringType.Name}.{field.Name}'";
15+
return $"Could not inject field {fieldDescription}, exception: {e}";
16+
}
1017
}
1118
}

Assets/Reflex/Exceptions/MethodInjectorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public MethodInjectorException(object obj, MethodInfo method, Exception e) : bas
1313
private static string BuildMessage(object obj, MethodInfo method, Exception e)
1414
{
1515
var parameters = method.GetParameters();
16-
var methodDescription = $"'{obj.GetType().Name}::{method.Name}'";
16+
var methodDescription = $"'{obj.GetType().Name}.{method.Name}'";
1717
var parametersDescription = $"'{string.Join(", ", parameters.Select(p => p.ParameterType.Name))}'";
1818
return $"Could not inject method {methodDescription} with parameters {parametersDescription}\n\n{e}";
1919
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using System;
2+
using System.Reflection;
23

34
namespace Reflex.Exceptions
45
{
56
internal sealed class PropertyInjectorException : Exception
67
{
7-
public PropertyInjectorException(Exception e) : base(e.Message)
8+
public PropertyInjectorException(PropertyInfo property, Exception e) : base(BuildMessage(property, e))
89
{
910
}
11+
12+
private static string BuildMessage(PropertyInfo property, Exception e)
13+
{
14+
var propertyDescription = $"'{property.DeclaringType.Name}.{property.Name}'";
15+
return $"Could not inject property {propertyDescription}, exception: {e}";
16+
}
1017
}
1118
}

Assets/Reflex/Injectors/FieldInjector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static void Inject(FieldInfo field, object instance, Container containe
1515
}
1616
catch (Exception e)
1717
{
18-
throw new FieldInjectorException(e);
18+
throw new FieldInjectorException(field, e);
1919
}
2020
}
2121
}

Assets/Reflex/Injectors/PropertyInjector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static void Inject(PropertyInfo property, object instance, Container co
1515
}
1616
catch (Exception e)
1717
{
18-
throw new PropertyInjectorException(e);
18+
throw new PropertyInjectorException(property, e);
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)