Skip to content

Commit

Permalink
Check and ignoring nulls when using reflection.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsc committed Dec 6, 2023
1 parent c62f79e commit 473f09b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ private static bool TryGetTupleName(ParameterInfo parameter, Type parameterType,
.FirstOrDefault(a =>
{
var attributeType = a.GetType();
return attributeType.Namespace == "System.Runtime.CompilerServices" &&
return attributeType != null &&
attributeType.Namespace == "System.Runtime.CompilerServices" &&
attributeType.Name == "TupleElementNamesAttribute";
});

if (tupleNameAttribute != null)
{
var propertyInfo = tupleNameAttribute.GetType()
.GetProperty("TransformNames", BindingFlags.Instance | BindingFlags.Public)!;
var tupleNames = propertyInfo.GetValue(tupleNameAttribute) as IList<string>;
.GetProperty("TransformNames", BindingFlags.Instance | BindingFlags.Public);
var tupleNames = propertyInfo?.GetValue(tupleNameAttribute) as IList<string>;
if (tupleNames?.Count > 0)
{
var args = parameterType.GetGenericArguments();
Expand Down

0 comments on commit 473f09b

Please sign in to comment.