Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullable annotations for IPropertyDescriptor.GetCustomAttribute #787

Merged
merged 1 commit into from Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/IPropertyDescriptor.cs
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
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
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
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
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
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