diff --git a/YamlDotNet/Serialization/IPropertyDescriptor.cs b/YamlDotNet/Serialization/IPropertyDescriptor.cs index d680684f..7739c736 100644 --- a/YamlDotNet/Serialization/IPropertyDescriptor.cs +++ b/YamlDotNet/Serialization/IPropertyDescriptor.cs @@ -33,7 +33,7 @@ public interface IPropertyDescriptor int Order { get; set; } ScalarStyle ScalarStyle { get; set; } - T GetCustomAttribute() where T : Attribute; + T? GetCustomAttribute() where T : Attribute; IObjectDescriptor Read(object target); void Write(object target, object? value); diff --git a/YamlDotNet/Serialization/PropertyDescriptor.cs b/YamlDotNet/Serialization/PropertyDescriptor.cs index e92a1221..32b82cce 100644 --- a/YamlDotNet/Serialization/PropertyDescriptor.cs +++ b/YamlDotNet/Serialization/PropertyDescriptor.cs @@ -62,7 +62,7 @@ public void Write(object target, object? value) baseDescriptor.Write(target, value); } - public T GetCustomAttribute() where T : Attribute + public T? GetCustomAttribute() where T : Attribute { return baseDescriptor.GetCustomAttribute(); } diff --git a/YamlDotNet/Serialization/TypeInspectors/ReadableFieldsTypeInspector.cs b/YamlDotNet/Serialization/TypeInspectors/ReadableFieldsTypeInspector.cs index 9e618687..e7f77c2e 100644 --- a/YamlDotNet/Serialization/TypeInspectors/ReadableFieldsTypeInspector.cs +++ b/YamlDotNet/Serialization/TypeInspectors/ReadableFieldsTypeInspector.cs @@ -70,10 +70,10 @@ public void Write(object target, object? value) fieldInfo.SetValue(target, value); } - public T GetCustomAttribute() where T : Attribute + public T? GetCustomAttribute() where T : Attribute { var attributes = fieldInfo.GetCustomAttributes(typeof(T), true); - return (T)attributes.FirstOrDefault(); + return (T?)attributes.FirstOrDefault(); } public IObjectDescriptor Read(object target) diff --git a/YamlDotNet/Serialization/TypeInspectors/ReadablePropertiesTypeInspector.cs b/YamlDotNet/Serialization/TypeInspectors/ReadablePropertiesTypeInspector.cs index 25484c97..90c3f248 100644 --- a/YamlDotNet/Serialization/TypeInspectors/ReadablePropertiesTypeInspector.cs +++ b/YamlDotNet/Serialization/TypeInspectors/ReadablePropertiesTypeInspector.cs @@ -84,10 +84,10 @@ public void Write(object target, object? value) propertyInfo.SetValue(target, value, null); } - public T GetCustomAttribute() where T : Attribute + public T? GetCustomAttribute() where T : Attribute { var attributes = propertyInfo.GetAllCustomAttributes(); - return (T)attributes.FirstOrDefault(); + return (T?)attributes.FirstOrDefault(); } public IObjectDescriptor Read(object target) diff --git a/YamlDotNet/Serialization/TypeInspectors/WritablePropertiesTypeInspector.cs b/YamlDotNet/Serialization/TypeInspectors/WritablePropertiesTypeInspector.cs index ebb8967b..88ebee05 100644 --- a/YamlDotNet/Serialization/TypeInspectors/WritablePropertiesTypeInspector.cs +++ b/YamlDotNet/Serialization/TypeInspectors/WritablePropertiesTypeInspector.cs @@ -85,10 +85,10 @@ public void Write(object target, object? value) propertyInfo.SetValue(target, value, null); } - public T GetCustomAttribute() where T : Attribute + public T? GetCustomAttribute() where T : Attribute { var attributes = propertyInfo.GetAllCustomAttributes(); - return (T)attributes.FirstOrDefault(); + return (T?)attributes.FirstOrDefault(); } public IObjectDescriptor Read(object target) diff --git a/YamlDotNet/Serialization/YamlAttributeOverridesInspector.cs b/YamlDotNet/Serialization/YamlAttributeOverridesInspector.cs index 1d88d7a9..1df5624d 100644 --- a/YamlDotNet/Serialization/YamlAttributeOverridesInspector.cs +++ b/YamlDotNet/Serialization/YamlAttributeOverridesInspector.cs @@ -95,7 +95,7 @@ public void Write(object target, object? value) baseDescriptor.Write(target, value); } - public T GetCustomAttribute() where T : Attribute + public T? GetCustomAttribute() where T : Attribute { var attr = overrides.GetAttribute(classType, Name); return attr ?? baseDescriptor.GetCustomAttribute();