Skip to content
Prev Previous commit
Next Next commit
Use pattern matching
  • Loading branch information
jkotas committed Jul 17, 2021
commit 10890e088cb08490034e8518d5817f44adccaf32
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value)
if (memberInfo == null)
throw new ArgumentNullException(nameof(memberInfo));

Type type;
if (memberInfo is FieldInfo field)
Type type = memberInfo switch
{
type = field.FieldType;
}
else if (memberInfo is PropertyInfo property)
{
type = property.PropertyType;
}
else
{
throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
}
FieldInfo field => field.FieldType,
PropertyInfo property => property.PropertyType,
_ => throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument)
};

_memberInfo = memberInfo;
_value = new CustomAttributeTypedArgument(type, value);
Expand Down