Skip to content

Commit

Permalink
Merge pull request #787 from meziantou/fix-nrt-ipropertydescriptor
Browse files Browse the repository at this point in the history
Fix nullable annotations for IPropertyDescriptor.GetCustomAttribute
  • Loading branch information
EdwardCooke committed Mar 11, 2023
2 parents 6c718ed + b84bca5 commit c44a46b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/IPropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface IPropertyDescriptor
int Order { get; set; }
ScalarStyle ScalarStyle { get; set; }

T GetCustomAttribute<T>() where T : Attribute;
T? GetCustomAttribute<T>() where T : Attribute;

IObjectDescriptor Read(object target);
void Write(object target, object? value);
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/PropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void Write(object target, object? value)
baseDescriptor.Write(target, value);
}

public T GetCustomAttribute<T>() where T : Attribute
public T? GetCustomAttribute<T>() where T : Attribute
{
return baseDescriptor.GetCustomAttribute<T>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public void Write(object target, object? value)
fieldInfo.SetValue(target, value);
}

public T GetCustomAttribute<T>() where T : Attribute
public T? GetCustomAttribute<T>() where T : Attribute
{
var attributes = fieldInfo.GetCustomAttributes(typeof(T), true);
return (T)attributes.FirstOrDefault();
return (T?)attributes.FirstOrDefault();
}

public IObjectDescriptor Read(object target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public void Write(object target, object? value)
propertyInfo.SetValue(target, value, null);
}

public T GetCustomAttribute<T>() where T : Attribute
public T? GetCustomAttribute<T>() where T : Attribute
{
var attributes = propertyInfo.GetAllCustomAttributes<T>();
return (T)attributes.FirstOrDefault();
return (T?)attributes.FirstOrDefault();
}

public IObjectDescriptor Read(object target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void Write(object target, object? value)
propertyInfo.SetValue(target, value, null);
}

public T GetCustomAttribute<T>() where T : Attribute
public T? GetCustomAttribute<T>() where T : Attribute
{
var attributes = propertyInfo.GetAllCustomAttributes<T>();
return (T)attributes.FirstOrDefault();
return (T?)attributes.FirstOrDefault();
}

public IObjectDescriptor Read(object target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void Write(object target, object? value)
baseDescriptor.Write(target, value);
}

public T GetCustomAttribute<T>() where T : Attribute
public T? GetCustomAttribute<T>() where T : Attribute
{
var attr = overrides.GetAttribute<T>(classType, Name);
return attr ?? baseDescriptor.GetCustomAttribute<T>();
Expand Down

0 comments on commit c44a46b

Please sign in to comment.