Skip to content

Commit

Permalink
Merge pull request #985 from EdwardCooke/ec-fixes
Browse files Browse the repository at this point in the history
Removes sealed from a number of classes and respects empty strings in enummember

+semver:fix
  • Loading branch information
EdwardCooke authored Sep 26, 2024
2 parents c664e43 + 6fa502a commit 7923dd8
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void HandleEnum(ITypeSymbol type)
if (enumMember != null)
{
var argument = enumMember.NamedArguments.FirstOrDefault(x => x.Key == "Value");
if (!string.IsNullOrWhiteSpace(argument.Value.Value as string))
if ((argument.Value.Value as string) != null)
{
memberValue = (string)argument.Value.Value!;
}
Expand Down
10 changes: 8 additions & 2 deletions YamlDotNet.Test/Analyzers/StaticGenerator/ObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public void EnumSerializationUsesEnumMemberAttribute()
public void EnumSerializationUsesEnumMemberAttributeWithEmptyValue()
{
var serializer = new StaticSerializerBuilder(new StaticContext()).Build();
var actual = serializer.Serialize(EnumMemberedEnum.EmptyValue);
Assert.Equal("EmptyValue", actual.TrimNewLines());
var actual = serializer.Serialize(new EnumMemberedEnumHarness { Test = EnumMemberedEnum.EmptyValue });
Assert.Equal("Test: ''", actual.TrimNewLines());
}

[Fact]
Expand All @@ -243,6 +243,12 @@ public void EnumSerializationUsesEnumMemberAttributeWithNullValue()
Assert.Equal("NullValue", actual.TrimNewLines());
}

[YamlSerializable]
public class EnumMemberedEnumHarness
{
public EnumMemberedEnum Test { get; set; }
}

[YamlSerializable]
public enum EnumMemberedEnum
{
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet.Test/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,8 @@ public void EnumSerializationUsesEnumMemberAttribute()
public void EnumSerializationUsesEnumMemberAttributeWithEmptyValue()
{
var serializer = new SerializerBuilder().Build();
var actual = serializer.Serialize(EnumMemberedEnum.EmptyValue);
Assert.Equal("EmptyValue", actual.TrimNewLines());
var actual = serializer.Serialize(new { Test = EnumMemberedEnum.EmptyValue });
Assert.Equal("Test: ''", actual.TrimNewLines());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace YamlDotNet.Serialization.ObjectFactories
/// <summary>
/// Creates objects using Activator.CreateInstance.
/// </summary>
public sealed class DefaultObjectFactory : ObjectFactoryBase
public class DefaultObjectFactory : ObjectFactoryBase
{
private readonly Dictionary<Type, ConcurrentDictionary<Type, MethodInfo[]>> stateMethods = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Wraps another <see cref="ITypeInspector"/> and applies caching.
/// </summary>
public sealed class CachedTypeInspector : TypeInspectorSkeleton
public class CachedTypeInspector : TypeInspectorSkeleton
{
private readonly ITypeInspector innerTypeDescriptor;
private readonly ConcurrentDictionary<Type, List<IPropertyDescriptor>> cache = new ConcurrentDictionary<Type, List<IPropertyDescriptor>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Aggregates the results from multiple <see cref="ITypeInspector" /> into a single one.
/// </summary>
public sealed class CompositeTypeInspector : TypeInspectorSkeleton
public class CompositeTypeInspector : TypeInspectorSkeleton
{
private readonly IEnumerable<ITypeInspector> typeInspectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// Wraps another <see cref="ITypeInspector"/> and applies a
/// naming convention to the names of the properties.
/// </summary>
public sealed class NamingConventionTypeInspector : TypeInspectorSkeleton
public class NamingConventionTypeInspector : TypeInspectorSkeleton
{
private readonly ITypeInspector innerTypeDescriptor;
private readonly INamingConvention namingConvention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Returns the properties of a type that are both readable and writable.
/// </summary>
public sealed class ReadableAndWritablePropertiesTypeInspector : TypeInspectorSkeleton
public class ReadableAndWritablePropertiesTypeInspector : TypeInspectorSkeleton
{
private readonly ITypeInspector innerTypeDescriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Returns the properties and fields of a type that are readable.
/// </summary>
public sealed class ReadableFieldsTypeInspector : ReflectionTypeInspector
public class ReadableFieldsTypeInspector : ReflectionTypeInspector
{
private readonly ITypeResolver typeResolver;

Expand All @@ -46,7 +46,7 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
.Select(p => (IPropertyDescriptor)new ReflectionFieldDescriptor(p, typeResolver));
}

private sealed class ReflectionFieldDescriptor : IPropertyDescriptor
protected class ReflectionFieldDescriptor : IPropertyDescriptor
{
private readonly FieldInfo fieldInfo;
private readonly ITypeResolver typeResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Returns the properties of a type that are readable.
/// </summary>
public sealed class ReadablePropertiesTypeInspector : ReflectionTypeInspector
public class ReadablePropertiesTypeInspector : ReflectionTypeInspector
{
private readonly ITypeResolver typeResolver;
private readonly bool includeNonPublicProperties;
Expand Down Expand Up @@ -60,7 +60,7 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
.Select(p => (IPropertyDescriptor)new ReflectionPropertyDescriptor(p, typeResolver));
}

private sealed class ReflectionPropertyDescriptor : IPropertyDescriptor
protected class ReflectionPropertyDescriptor : IPropertyDescriptor
{
private readonly PropertyInfo propertyInfo;
private readonly ITypeResolver typeResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override string GetEnumValue(object enumValue)
if (enumMembers.Length > 0)
{
var attribute = enumMembers[0].GetCustomAttribute<EnumMemberAttribute>();
if (!string.IsNullOrWhiteSpace(attribute?.Value))
if (attribute?.Value != null)
{
result = attribute.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.TypeInspectors
/// <summary>
/// Returns the properties of a type that are writable.
/// </summary>
public sealed class WritablePropertiesTypeInspector : ReflectionTypeInspector
public class WritablePropertiesTypeInspector : ReflectionTypeInspector
{
private readonly ITypeResolver typeResolver;
private readonly bool includeNonPublicProperties;
Expand Down Expand Up @@ -61,7 +61,7 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
.ToArray();
}

private sealed class ReflectionPropertyDescriptor : IPropertyDescriptor
protected class ReflectionPropertyDescriptor : IPropertyDescriptor
{
private readonly PropertyInfo propertyInfo;
private readonly ITypeResolver typeResolver;
Expand Down

0 comments on commit 7923dd8

Please sign in to comment.